Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Forcing a Text Box to accept only Numbers

How can I make a text box to accept only numbers or text in a specific format
(eg. for Post Codes)
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Forcing a Text Box to accept only Numbers

Assuming the textbox is in a form then in the code behind the form you can
write a short procedure.

Assuming the TextBox is called MyTextBox then

Sub MyTextBox_Change()

if not MyTextBox.Value like "##" then

MyTextBox.Value = ""

MsgBox "This is not a number", vbOKOnly, "Dont type text"

end if

end sub

This will be triggered as the user types.
If you prefer to wait until the user has completed his/her mistake then use
_afterUpdate() instead

Hope this helps

Nick Shinkins




"Mihalis" wrote:

How can I make a text box to accept only numbers or text in a specific format
(eg. for Post Codes)

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Forcing a Text Box to accept only Numbers


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 Else
Application.EnableEvents = False
KeyAscii = 0
Application.EnableEvents = True
Beep
End Select


End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Mihalis" wrote in message
...
How can I make a text box to accept only numbers or text in a specific

format
(eg. for Post Codes)



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
IF formula to accept or reject based on numbers entered. crabflinger Excel Discussion (Misc queries) 6 April 3rd 09 10:10 PM
Forcing Text Kirk P. Excel Discussion (Misc queries) 2 September 26th 06 07:57 PM
Format cells to only accept numbers cradino Excel Discussion (Misc queries) 4 July 22nd 06 03:46 PM
Forcing Excel to retain red text? Sigi Rindler Excel Discussion (Misc queries) 1 March 23rd 06 08:33 AM
cell format in Excel 2002 SP3 will not accept long numbers spkersh Excel Worksheet Functions 1 October 27th 05 07:22 PM


All times are GMT +1. The time now is 05:10 PM.

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"