Notifications
Clear all

Impedir Digitação Após a Vírgula

4 Posts
2 Usuários
0 Reactions
1,318 Visualizações
(@pedrobb)
Posts: 0
New Member
Topic starter
 

Pessoal,
Em uma TextBox que aceita apenas Números e 01 vírgula, preciso impedir a Digitação após a Segunda Casa decimal.
Exemplo: 123,55 (correto - 2 casas) 123,558 (errado - 3 casas)
Grato,
Pedro

 
Postado : 09/12/2019 7:51 am
(@deciog)
Posts: 0
New Member
 

pedrobb

O correto é postar um modelo, mas confere com essa formula ajuda na validação ou formatação

=SEERRO(NÚM.CARACT(EXT.TEXTO(A1;LOCALIZAR(",";A1;1)+1;15))<=2;1)

Se foi útil, clique na mãozinha é uma forma de agradecimento

Decio

 
Postado : 09/12/2019 10:44 am
(@pedrobb)
Posts: 0
New Member
Topic starter
 

Décio,
Obrigado pela ajuda.
O problema é que preciso de função para usar em Formulário, em uma Caixa de Texto (TextBox).

Pedro

 
Postado : 09/12/2019 4:54 pm
(@pedrobb)
Posts: 0
New Member
Topic starter
 

Resolvido pelo Basole. Vide Eventos KeyPress e Change:

Private Sub TxtValor_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 44, 8, 48 To 57
If KeyAscii = 44 Then If InStr(1, TxtValor, ",", vbTextCompare) > 0 Then KeyAscii = 0
Case Else
KeyAscii = 0
End Select
End Sub


Private Sub TxtValor_Change()
Dim bMax As Byte
   bMax = VBA.Len(TxtValor.Value)
    If VBA.InStr(1, TxtValor.Value, ".", vbTextCompare) > 0 Or _
       VBA.InStr(1, TxtValor.Value, ",", vbTextCompare) > 0 Then
        If TxtValor.MaxLength = bMax + 1 Or TxtValor.MaxLength = bMax Then
        Else
            TxtValor.MaxLength = bMax + 2
        End If
    Else
         TxtValor.MaxLength = 0
    End If
End Sub
 
Postado : 11/12/2019 6:57 pm