Highlight cells based upon multiple strings or file with strings

wordplay75

New Member
Joined
Mar 13, 2014
Messages
1
I am looking to search a worksheet for multiple strings and highlight each cell that contains one of those strings. For example, if the sheet has a column named color and each row has a color (e.g., red, green, blue) I would like the macro to either take multiple strings such as "blue", "red", and "green" and highlight all of the cells containing the strings, pull the strings from a file, or be able to add the strings directly into the code. I found the following code below that does what I want but it only does one string at a time and requires user input. I want to be able to copy 30+ unique strings into a prompt or into the code and receive results. Thank you for your help.

  1. Sub</SPAN> find_highlight() </SPAN>
  2. Dim</SPAN> strUI </SPAN>As</SPAN> String</SPAN>
  3. Dim</SPAN> strFirstAdd </SPAN>As</SPAN> String</SPAN>
  4. Dim</SPAN> rFound </SPAN>As</SPAN> Range </SPAN>
  5. strUI = Application.InputBox("What to find?") </SPAN>
  6. If</SPAN> strUI = "False" </SPAN>Or</SPAN> strUI = vbNullString </SPAN>Then</SPAN> Exit </SPAN>Sub</SPAN>
  7. With</SPAN> Worksheets(1).Cells </SPAN>
  8. Set</SPAN> rFound = .Find(strUI, LookIn:=xlValues) </SPAN>
  9. If</SPAN> Not</SPAN> rFound </SPAN>Is</SPAN> Nothing</SPAN> Then</SPAN>
  10. strFirstAdd = rFound.Address </SPAN>
  11. Do</SPAN>
  12. With</SPAN> rFound.Interior </SPAN>
  13. .ColorIndex = 8 </SPAN>
  14. .Pattern = xlSolid </SPAN>
  15. .PatternColorIndex = xlAutomatic </SPAN>
  16. End With</SPAN>
  17. Set</SPAN> rFound = .FindNext(rFound) </SPAN>
  18. Loop</SPAN> While</SPAN> Not</SPAN> rFound </SPAN>Is</SPAN> Nothing</SPAN> And</SPAN> rFound.Address <> strFirstAdd </SPAN>
  19. End</SPAN> If</SPAN>
  20. End With</SPAN>
  21. End Sub</SPAN>
 
Last edited:

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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