Thread: textbox
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
tamsin tamsin is offline
external usenet poster
 
Posts: 4
Default textbox

Is there an easy way of only allowing numbers and one
decimal point to be entered in a textbox?

I've found a rather long winded way of solving the number
bit (see code below) but checking each previously entered
character to see if its a decimal point has proved to be a
problem; and there must be a simpler way!

Private Sub TextBox1_Change()
If TextBox1.Text < "" Then
If Asc(Right(TextBox1.Text, 1)) < 48 _
Or Asc(Right(TextBox1.Text, 1)) 57 Then
TextBox1.Text = _
Left(TextBox1.Text, TextBox1.TextLength - 1)
End If
End If
End Sub