Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have over 100 text boxes on my excel VBA form and
I request for help on how i can write "is numeric"
validation for all the boxes together without having
to write for every/each text box. thanks
Posted

Hi,
I assume you left thos 100 Textbox(s) (Name) default. If so you can acheive this by writing a simple VBA macro code like mentioned below. If the value is not numeric this pops the name of the textbox. you can change the funcionality which suits for you.
VB
Private Sub CheckIsNumeric()
Dim i As Integer
Dim flag As Boolean
For i = 1 To 100
   flag = IsNumeric(Controls("TextBox" & i).Text)
   If flag = False Then
       MsgBox ("TextBox" & i & " is not numeric")
   Exit For
   End If
Next
End Sub

Hope I understood your question correctly. Change the value 100 based on your textbox count.

Thanks
Sriram.B
 
Share this answer
 
Comments
Maciej Los 14-Aug-13 8:14am    
Please, test it:
Sub Test()
Dim s As String

s = "&1"
MsgBox "'" & s & "' is number: '" & IsNumeric(s) & "'", vbInformation, "Message"
s = "523d9"
MsgBox "'" & s & "' is number: '" & IsNumeric(s) & "'", vbInformation, "Message"
s = "122e5"
MsgBox "'" & s & "' is number: '" & IsNumeric(s) & "'", vbInformation, "Message"
End Sub

Using IsNumeric() function validation failed ;(
Sriram Bala 14-Aug-13 8:24am    
I am trying to replicate the error you pasted above. I am not getting that. I placed a command button in the form and wrote the above piece of code inside Private Sub CommandButton1_Click(). However Member 10208918303 should include empty text validation logic like you mentioned. Thanks. :-)
Im very grateful but just wondering where exactly to place the code. Im just a beginner so Im requesting for more elaborations please. thanks
 
Share this answer
 
Comments
Maciej Los 15-Aug-13 15:33pm    
This is not an answer. Please delete it to avoid down-voting. To post a question or comment, use "Have a question or comment" widget.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900