Sunday, 31 December 2017

How to validate a textbox while entering data in VBA | Data validation in VBA user forms

You can add below code on the event of textbox_keypress, textbox_enter, etc to validate the entry while user enters the data into the textbox.

Function ValidateTextboxForNumbersOnly(ByRef tb As MSForms.TextBox)
'Purpose : To validate and clear data in text box if value is not numeric
    If IsNumeric(tb.Value) = False Then tb.Value = ""
End Function