Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default limit textbox to numbers or spaces?

I have a bit of code that tells the user that only numbers are allowed
in this textbox after they put in a letter, I ammended it to also allow
nothing as it was flagging up when nothing was entered.
How do i make it so i can have say a telephone number with a space or 2
in it?


Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(TextBox9.Value) = True Or TextBox9.Value = "" _ Then
Else
MsgBox "This box must only contain numbers!", vbInformation
TextBox9.Value = ""
Exit Sub
End If
End Sub

Thanks for looking
CAA


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default limit textbox to numbers or spaces?

John,

Why not trap them as input

Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 48 To 57 'Nos 0 - 9
Exit Sub
Case 32 ' space
Case Else
Application.EnableEvents = False
KeyAscii = 0
Application.EnableEvents = True
Beep
End Select

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"CAA " wrote in message
...
I have a bit of code that tells the user that only numbers are allowed
in this textbox after they put in a letter, I ammended it to also allow
nothing as it was flagging up when nothing was entered.
How do i make it so i can have say a telephone number with a space or 2
in it?


Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(TextBox9.Value) = True Or TextBox9.Value = "" _ Then
Else
MsgBox "This box must only contain numbers!", vbInformation
TextBox9.Value = ""
Exit Sub
End If
End Sub

Thanks for looking
CAA


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default limit textbox to numbers or spaces?

Thanks Bob,
That's Fantastic
That snippet is going straight in my favourite bits of code.

Cheers
CAA


---
Message posted from http://www.ExcelForum.com/

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Character limit in textbox Ashley Excel Worksheet Functions 1 September 10th 08 01:33 AM
Removing spaces at the end of numbers Chris T. Excel Worksheet Functions 5 May 5th 07 06:22 AM
How do I convert numbers stored as text with spaces to numbers Baffuor Excel Discussion (Misc queries) 1 May 24th 05 07:39 AM
number of spaces between numbers David Excel Discussion (Misc queries) 1 March 11th 05 08:39 PM
Limit input in a textbox James Agostinho Excel Programming 2 September 10th 03 03:10 PM


All times are GMT +1. The time now is 07:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"