Hello D3Pratt,
You can reuse a validation routine in the Exit event. You need to create a function that will return a Boolean value as a result of the validation. This can be applied to the Cancel variable in the Exit event. Copy this code into a standard VBA module.
Function ValidateTextBox(ByRef TB As MSForms.TextBox) As Boolean
If Trim(TB.Value) = "" Then Exit Function
If Not IsNumeric(TB) Then
MsgBox "Please enter only Numeric values."
ValidateTextBox = True
TB.SelStart = 0
TB.SelLength = Len(TB.Value)
End If
End Function
The macro will validate that the entry is numeric. Spaces and empty entries are ignored. Now you can use this same line of code below (in blue) in every TextBox_Exit event.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Cancel = ValidateTextBox(ActiveControl)
End Sub
Bookmarks