Search for pattern of numbers/letters and wildcard

HalfricanHokie

New Member
Joined
Jun 26, 2014
Messages
2
I would like to search for a certain pattern that appears in a cell. For example, I have certain cells that begin with a 7 digit project code (Ex: "1234567 - Project Red"). I was planning to use an IF inside a FOR loop and then do an action when I find the cell with the pattern. I thought I remember it being something like Format(########*) so that I have the wildcard on the end since there is more than just the numbers.

If someone knows how to do this I would really appreciate it! Also, if you are familiar with how to make other patterns work such as Number-Letter-Number or Capital-Lowercase-Capital, that would be great to know!

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I would like to search for a certain pattern that appears in a cell. For example, I have certain cells that begin with a 7 digit project code (Ex: "1234567 - Project Red"). I was planning to use an IF inside a FOR loop and then do an action when I find the cell with the pattern. I thought I remember it being something like Format(########*) so that I have the wildcard on the end since there is more than just the numbers.

If someone knows how to do this I would really appreciate it! Also, if you are familiar with how to make other patterns work such as Number-Letter-Number or Capital-Lowercase-Capital, that would be great to know!
What you want to use is the Like operator, something like this for your example..

If {CellContent} Like "#######*" The

where CellContent is whatever method you now use to retrieve the value in the cell you are examining. As for the second part of your question, look up the Like operator in the VBA help files (put the text cursor next to or inside of the work Like in your code and press F1). Also, once you learn how to form patterns for the Like operator, you may find the code I posted in my mini-blog article here to be of use or interest...

<!-- title / author block -->Find a text substring that matches a given "pattern"
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top