Function for Regular Expressions in Excel Macro

This post will explain on how to create an Excel Macro Function for applying it to a cell value and extract the first Match on the cell calling the function. First we need to open the Macro Editor (Ctrl + F11) and add a new module, this is quite straight forward. Then we should add the following code on this new module:

 

 

This code basically receive two Range Object inputs, one correspond to the cell we want to convert and the second one to the regular expression. The Macro will test the regular expression and in case it pass the first match will be returned, otherwise a generic message of “Not matched” will be displayed.

 

2016-08-09_17-21-45

 

Above you have an example of the output!

Loading Facebook Comments ...

Leave a Reply

Your email address will not be published. Required fields are marked *