Visual Basic for Applications/Validate with the Like Operator

Summary
'''This VBA example can be run in any of the commonly used Microsoft Office applications. The examples on this page make use of the Like operator to compare strings. The first example shows how to check that a string conforms to the correct format of the United Kingdom's National Insurance Number (NINO), a number used in much the same way as the US Social Security Number (SSN). The rules for the format are clear so it makes a good example. Unlike examples elsewhere in this set that check for illegal characters while they are being entered, this method is carried out only when the user has completed the entry.'''

The VBA Code

 * The code needs a user form called Userform1, two text boxes, TextBox1 and TextBox2, and a command button called CommandButton1. Set the UserForm1 property ShowModal to false for convenient study. Copy the code below into the three respective modules and save the workbook with an xlsm file suffix.
 * When the workbook is opened, the user form will be displayed. Type a number format into TextBox1 and when complete, press the tab key to move to the next textbox. If the number format is correct then the insertion point will move, but if not it will stay in the faulty text ready for correction.  Setting the Cancel argument of BeforeUpdate to true prevents the move.
 * Note that the Before_Update event will not run at all unless a change has been made the text since the last time that the insertion point entered the box.  So, to labor the point, after leaving the box, if the user clicks in it again without changes, the event does not run when moving on.   If this poses a problem then consider the use of the Exit event for testing.
 * See also Input Boxes for a number of other validation-related procedures.

Code Changes
There are no changes so far.