Hello experts,
I am quite novice to VBA and any help from you would be highly appreciated.
I have 44 text boxes in my user form which I need only to accept numeric values. Every text box name has a "Quantity" part (ex. InhouseQuantityTextBox, PurchasedMaterialQuantity,etc.), but, they are not numbered from 1-44. Other text boxes in the user form should behave normally. I have two userforms of this kind and I want to apply the same condition to the other user form as well. Is there a way to make all these quantity text boxes accept only numeric values. If you could explain an answer in the simplest way, I would be much grateful as I couldn't modify most of the answers published in the internet because I couldn't understand them.
This is the code I used to make one text box accept only numeric values, but repeating it for 44 times is a headache.
Thanks a lot in advance
End Sub
I am quite novice to VBA and any help from you would be highly appreciated.
I have 44 text boxes in my user form which I need only to accept numeric values. Every text box name has a "Quantity" part (ex. InhouseQuantityTextBox, PurchasedMaterialQuantity,etc.), but, they are not numbered from 1-44. Other text boxes in the user form should behave normally. I have two userforms of this kind and I want to apply the same condition to the other user form as well. Is there a way to make all these quantity text boxes accept only numeric values. If you could explain an answer in the simplest way, I would be much grateful as I couldn't modify most of the answers published in the internet because I couldn't understand them.
This is the code I used to make one text box accept only numeric values, but repeating it for 44 times is a headache.
VBA Code:
Private Sub MaterialQuantityTextBox_Change()
If TypeName(Me.ActiveControl) = "TextBox" Then
With Me.ActiveControl
If Not IsNumeric(.Value) And .Value <> vbNullString Then
MsgBox "Sorry, only numbers allowed"
.Value = vbNullString
End If
End With
End If
Thanks a lot in advance
End Sub