Excelnoub
Member
Good day everyone,
I know there is a VBA for TextBox (OnlyNumbers) but is there a VB code that will do the same thing but for cells...
Example:
[pre]
[/pre]
Code
I am trying to come up with a code in my Target, Range("D5:D30") to have numbers only and if there is a letter then the msg error will say MsgBox "Sorry, only numbers allowed."
Is this possible or I need to use another alternative ie: Data Validation?
Thank you...
Excelnoub
I know there is a VBA for TextBox (OnlyNumbers) but is there a VB code that will do the same thing but for cells...
Example:
[pre]
Code:
Code
Private Sub OnlyNumbers()
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
End Sub
Code
I am trying to come up with a code in my Target, Range("D5:D30") to have numbers only and if there is a letter then the msg error will say MsgBox "Sorry, only numbers allowed."
Is this possible or I need to use another alternative ie: Data Validation?
Thank you...
Excelnoub