I've found the below code which will prevent anything other than numbers being entered into the text boxes within my userform. However this means that a negative (-) symbol cannot be used. Is there any way I can keep the restriction but allow the negative symbol to also be used?
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
Bookmarks