![]() |
|
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
Hi all, what VB code do I put in so that users can only enter numbers into a textbox? Janie |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Try something like: -
If Not IsNumeric(TextBox1.Text) Then ... |
|
|
|
|
|
#3 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi.
Assume the textbox is on an userform.
Regards, Colo [ This Message was edited by: Colo on 2002-04-26 01:17 ] |
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
That's great, it kind of works, but the SetFocus bit won't work? I'd like it to remain in Textbox1 so they can try again. Do you know what I'm doing wrong? I've put the following code in Textbox1's exit event:
If Not IsNumeric(TextBox1.Text) Then MsgBox ("Must be a number") TextBox1.SetFocus TextBox1.Value = "" Else TextBox2.SetFocus End If Thanks Janie |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
Oooh that's great code, that does exactly it, thanks Colo!
Janie xx |
|
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
Not sure as I can't test this at the minute, but it might be better to do that when a command button is clicked- ie stick all your checking code in the Click event.
Or, you could try Colo's which I think will check as the user types in the textbox. I see you already have [ This Message was edited by: Mudface on 2002-04-26 01:25 ] |
|
|
|
|
|
#7 |
|
Board Regular
Join Date: Apr 2002
Posts: 76
|
Thanks Mudface, I'm still using your code on another part of it though. Thanks for the advice
Janie |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|