Like operator

Like operator

4 December 2016

The Like operator allows you to match a string to a pattern in Excel VBA.

This blog describes usage of the VBA Like operator and, as a bonus, mentions how you can use the question mark ? and asterisk * for pattern matching in many Excel functions

The VBA Like operator uses the following patterns:

  • ? (question mark) - Matches any single character.
  • * (asterisk) - Matches zero or more characters.
  • # (number or hash sign) - Any single digit.
  • [abc] - Characters enclosed in brackets allows you to match any single character in the string.
  • [!abc] - The exclamation mark (!) matches any single character not in the string.
  • [A-Z] - The hyphen lets you specify a range of characters.