Forum Discussion
pascalemarquis
May 05, 2022Copper Contributor
Excel Data Validation using regular expressions
Excel VBA Regex function to match strings https://www.ablebits.com/office-addins-blog/regex-match-excel/ As indicate in here: https://www.ablebits.com/office-addins-blog/regex-match-excel/ ...
HansVogelaar
May 05, 2022MVP
A macro is a procedure (Sub) without arguments in a standard module.
A function is not a macro, so it will not be listed under macros.
You can use the function in cell formulas. The Ablebits page gives some examples.
And you can use that in data validation. I'll take their SKU example.
Let's say you want to enter SKUs in A2:A12.
Select B2.
Enter the formula =OR(A2="",RegExpMatch(A2,"\b[A-Z]{2}-\d{3}\b"))
Fill down to B12.
On the Data tab of the ribbon, click Data Validation.
Select Custom, and enter the formula =B2 in the box.
If you wish, enter an error message in the Error Alert tab.
Click OK.