Página 1 de 1
Digitar somente numeros em um textbox [RESOLVIDO]
Enviado: Seg Ago 01, 2011 11:48 am
por Edu
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
Re: Digitar somente numeros em um textbox
Enviado: Seg Ago 01, 2011 12:17 pm
por JValq
Boa tarde,
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
Abraço
Re: Digitar somente numeros em um textbox
Enviado: Qui Ago 04, 2011 7:57 pm
por geroeane
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
Re: Digitar somente numeros em um textbox
Enviado: Qui Ago 04, 2011 8:37 pm
por Melo
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?
Re: Digitar somente numeros em um textbox
Enviado: Seg Ago 08, 2011 11:28 pm
por Mauro Coutinho
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
Re: Digitar somente numeros em um textbox
Enviado: Dom Out 02, 2016 3:19 am
por Pedro Jhonata
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
Enviado: Ter Out 01, 2019 1:21 pm
por Thigodoy
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