-2
Private Sub TNumero_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If (KeyAscii < 44 Or KeyAscii > 57) Then

    If KeyAscii <> 8 Then
    If KeyAscii <> 13 Then

    KeyAscii = 0

    MsgBox "É permitido somente números!", vbCritical, "ERRO"

End If
End If
End If

If KeyAscii = 45 Or KeyAscii = 46 Or KeyAscii = 47 Then
    KeyAscii = 0
    MsgBox "É permitido somente números!", vbCritical, "ERRO"
End If

End Sub

1 Resposta 1

0

O KeyAscii é representação em decimal do ASCII. Você pode consultar uma tabela ASCII e fazer as alterações necessárias.

Creio eu que isto seria suficiente, em teoria, nem sei que linguagem é essa, então pode ter algo errado:

Private Sub TNumero_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

If (KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 90 And KeyAscii < 97) Or KeyAscii > 122) Then

    If KeyAscii <> 8 Then
    If KeyAscii <> 13 Then

     KeyAscii = 0

    MsgBox "É permitido somente números!", vbCritical, "ERRO"

End If
End If
End If

O objetivo do KeyAscii < 48 Or (KeyAscii > 57 And KeyAscii < 65) Or (KeyAscii > 90 And KeyAscii < 97) Or KeyAscii > 122 é que valores que estão fora do intervalo de 0-9, A-Z e a-z seja apresentado a mensagem.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .