Searching for patterns of text with VBA

cheoksoon

Board Regular
Joined
Aug 25, 2016
Messages
56
Hi there,

How do I search for a pattern of text in cell using VBA?

I've looked into the instr and find method but this still eludes me.

For example, I've got a list of clients with special IDs attached next to their names. (i.e. John Smith ABC1234).

How do I search the cells to determine if the special ID is present (i.e. ABC1234, GUY4321, GAL0987, etc.) using VBA?

Thanks!
 
There seems to be a little confusion. When talking about duplicates, I was never referring to IDs, I was referring to names only.
Could you re-visit my questions 2, 3 and 4 and answer only in relation to duplicate names?

Sorry,

2. Yes, the duplicate number is always in parenthesis

3. Yes, they are always at the end

4. No, it might go up to 2 or 3, but not 897.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
1. Yeap, all my unique IDs are 3 letters followed by 4 digits.
2. Yes, the duplicate number is always in parenthesis

3. Yes, they are always at the end

4. No, it might go up to 2 or 3, but not 897.
In that case, if the duplicate name number would always be less than 10, see if this does what you want.

Excel Workbook
AB
1Laura Hill ABC1923TRUE
2John Smith ABC1283TRUE
3Jennifer MartinFALSE
4Kate Doe GUY4372TRUE
5John Doe GAL0987TRUE
6GAL4321 Sarah JonesTRUE
7Ann Louise SmithFALSE
8Michael Douglas (GHY7656)TRUE
9HUJ9899 / Kim MattersonTRUE
10John Doe(2)FALSE
11GUY6789Richard SmithTRUE
12John Doe GAL0987(8)TRUE
Check if ID (2)
 
Upvote 0
In that case, if the duplicate name number would always be less than 10, see if this does what you want.

Check if ID (2)

AB
1Laura Hill ABC1923TRUE
2John Smith ABC1283TRUE
3Jennifer MartinFALSE
4Kate Doe GUY4372TRUE
5John Doe GAL0987TRUE
6GAL4321 Sarah JonesTRUE
7Ann Louise SmithFALSE
8Michael Douglas (GHY7656)TRUE
9HUJ9899 / Kim MattersonTRUE
10John Doe(2)FALSE
11GUY6789Richard SmithTRUE
12John Doe GAL0987(8)TRUE

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:199px;"><col style="width:108px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
B1=ISNUMBER(AGGREGATE(15,6,FIND({0,1,2,3,4,5,6,7,8,9},LEFT(A1,LEN(A1)-3)),1))

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4


Yeap, that will definitely work! :)

Thanks for all the help.
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,320
Members
449,218
Latest member
Excel Master

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