Vídeo recomendado
https://youtu.be/diWPPPhW-9E
https://youtu.be/diWPPPhW-9E
Digitar somente numeros em um textbox [RESOLVIDO]
Digitar somente numeros em um textbox [RESOLVIDO]
Ola teria como fazer uma macro ou funcao para que um textbox so aceite numeros seguido de "."(ponto) ou ","(virgula)
se houver ficarei muito grato
se houver ficarei muito grato
Editado pela última vez por Edu em Qua Ago 10, 2011 10:46 am, em um total de 1 vez.
Re: Digitar somente numeros em um textbox
Boa tarde,
Veja se este código ajuda:
Abraço
Veja se este código ajuda:
Código: Selecionar todos
Private Sub TextBox1_Change()
If Not IsNumeric(TextBox1.Text) Then TextBox1.Text = Empty
End Sub
Re: Digitar somente numeros em um textbox
veja se ajuda.
Select Case KeyAscii
Case 8 'Backspace (seta de apagar)
Case 48 To 57 'Números de 0 a 9
Case 44 'Vírgula
If InStr(LarguraQuadrado.Text, ",") Then 'Se o campo já tiver vírgula então ele não adiciona
KeyAscii = 0 'Não adiciona a vírgula caso ja tenha
Else
KeyAscii = 44 'Adiciona uma vírgula
End If
Case Else
KeyAscii = 0 'Não deixa nenhuma outra caractere ser escrito
End Select
Select Case KeyAscii
Case 8 'Backspace (seta de apagar)
Case 48 To 57 'Números de 0 a 9
Case 44 'Vírgula
If InStr(LarguraQuadrado.Text, ",") Then 'Se o campo já tiver vírgula então ele não adiciona
KeyAscii = 0 'Não adiciona a vírgula caso ja tenha
Else
KeyAscii = 44 'Adiciona uma vírgula
End If
Case Else
KeyAscii = 0 'Não deixa nenhuma outra caractere ser escrito
End Select
Re: Digitar somente numeros em um textbox
Boa noite
Estou usando em meu projeto o seguinte para aceitar somente Numeros
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim strValid As String
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
' ESTE A BAIXO É PARA ESPECIFICAR QUE A CADA 3 NUMEROS COLOCAR UM TRAÇO (-) E DEPOIS MAIS 4
If Len(txtPlaca) = 3 Or Len(txtPlaca) = 4 Then
txtPlaca.Text = txtPlaca.Text & "-"
SendKeys "{End}", True
End If
Aproveito para PERGUNTAR
Como ficaria para digitar em uma TextBox uma placa, ex: Obrigar a Digitar somente (3) Letras e gerar o Traço (-) e depois aceitar os 4 numeros.
Como ficaria?
Estou usando em meu projeto o seguinte para aceitar somente Numeros
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim strValid As String
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
' ESTE A BAIXO É PARA ESPECIFICAR QUE A CADA 3 NUMEROS COLOCAR UM TRAÇO (-) E DEPOIS MAIS 4
If Len(txtPlaca) = 3 Or Len(txtPlaca) = 4 Then
txtPlaca.Text = txtPlaca.Text & "-"
SendKeys "{End}", True
End If
Aproveito para PERGUNTAR
Como ficaria para digitar em uma TextBox uma placa, ex: Obrigar a Digitar somente (3) Letras e gerar o Traço (-) e depois aceitar os 4 numeros.
Como ficaria?
- Mauro Coutinho
- Jedi
- Mensagens: 1561
- Registrado em: Sáb Mar 13, 2010 8:10 pm
- Localização: São José dos Pinhais - Pr
Re: Digitar somente numeros em um textbox
Melo, pelas minhas pesquisas e conhecimento, o ideal seria crair uma Function expecifica, mas como ainda preciso estudar um pouco mais a possibilidade, criei uma forma paliativa, com a utilização de 02 Textbox, de uma olhada e veja se ajuda.
TextBox- Somente Letras e Numeros
viewtopic.php?f=17&t=1206
[]s
TextBox- Somente Letras e Numeros
viewtopic.php?f=17&t=1206
[]s
-
- Colaborador
- Mensagens: 33
- Registrado em: Sex Abr 22, 2016 5:54 pm
Re: Digitar somente numeros em um textbox
Melo escreveu:Boa noite
Estou usando em meu projeto o seguinte para aceitar somente Numeros
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim strValid As String
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
' ESTE A BAIXO É PARA ESPECIFICAR QUE A CADA 3 NUMEROS COLOCAR UM TRAÇO (-) E DEPOIS MAIS 4
If Len(txtPlaca) = 3 Or Len(txtPlaca) = 4 Then
txtPlaca.Text = txtPlaca.Text & "-"
SendKeys "{End}", True
End If
Aproveito para PERGUNTAR
Como ficaria para digitar em uma TextBox uma placa, ex: Obrigar a Digitar somente (3) Letras e gerar o Traço (-) e depois aceitar os 4 numeros.
Como ficaria?
Muito bom, Melo!
Re: Digitar somente numeros em um textbox
Melo escreveu: ↑Qui Ago 04, 2011 8:37 pm Boa noite
Estou usando em meu projeto o seguinte para aceitar somente Numeros
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim strValid As String
strValid = "0123456789"
If InStr(strValid, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
' ESTE A BAIXO É PARA ESPECIFICAR QUE A CADA 3 NUMEROS COLOCAR UM TRAÇO (-) E DEPOIS MAIS 4
If Len(txtPlaca) = 3 Or Len(txtPlaca) = 4 Then
txtPlaca.Text = txtPlaca.Text & "-"
SendKeys "{End}", True
End If
Aproveito para PERGUNTAR
Como ficaria para digitar em uma TextBox uma placa, ex: Obrigar a Digitar somente (3) Letras e gerar o Traço (-) e depois aceitar os 4 numeros.
Como ficaria?
Para cada textbox terei que colocar essa Private Sub substituindo pelo nome da textbox? ou tem como fazer um global? como seria