Search for specific strings - then highlight cells

fddekker

Board Regular
Joined
Jun 30, 2008
Messages
86
Office Version
  1. 365
Platform
  1. Windows
I would like to find cells that contains the string PO (capital letters) on a worksheet and then highlight those cells in a specific color with a macro to be added to the ribbon.
It should not highlight cells where the string is part of a word, e.g. CORPORATE. The most likely strings would be:
POxxx
PO xxxxxxx
PO# xxxxx
PO#xxxx
(With x being numbers)
The string could be at the start or the middle of cells.

Any help on what the best syntax is to find these strings that would ignore the unwanted strings?

Thanks in advance.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
look for .PO where . is a single blank space

and look for if left(A1,=3)="PO." or "PO#" . single space

run down the column checking each cell in turn, where a match is found colour the cell
 
Upvote 0
Thanks. But the problem I am having is to fond a syntax that will find the 4 sub-strings in both the middle or beginning of cell contents. This UDF from Gary's Student: (note that 1 is where the UDF finds the string, and 0 if no string was found.)

UDFPO_zps7978e4aa.png



have the same answers as my attempts:
POSearch_zpsdd6ea1ad.png


It finds the sub-strings when they are NOT at the beginning of the cell. (A8 and A10 should also be found)
Any comments on where I go wrong?

Thanks in advance!
 
Upvote 0
one PO two5 PO1
3PO423PO41
3PO#23PO#1
SPOT2SPOT0
POT2POT0 PO1
three PO7 PO1 PO1
SPO2SPO0 PO#1
#PO1
1PO11
9PO91
APOA0
ZPOZ0
using search for "PO" and
pulling out the PO and one
character around it
and using a lookup table
rejects SPOT POT SPO

<colgroup><col><col span="4"><col><col><col><col><col><col><col><col><col><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,641
Messages
6,125,981
Members
449,276
Latest member
surendra75

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