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.
- Sub</SPAN> find_highlight() </SPAN>
- Dim</SPAN> strUI </SPAN>As</SPAN> String</SPAN>
- Dim</SPAN> strFirstAdd </SPAN>As</SPAN> String</SPAN>
- Dim</SPAN> rFound </SPAN>As</SPAN> Range </SPAN>
- strUI = Application.InputBox("What to find?") </SPAN>
- If</SPAN> strUI = "False" </SPAN>Or</SPAN> strUI = vbNullString </SPAN>Then</SPAN> Exit </SPAN>Sub</SPAN>
- With</SPAN> Worksheets(1).Cells </SPAN>
- Set</SPAN> rFound = .Find(strUI, LookIn:=xlValues) </SPAN>
- If</SPAN> Not</SPAN> rFound </SPAN>Is</SPAN> Nothing</SPAN> Then</SPAN>
- strFirstAdd = rFound.Address </SPAN>
- Do</SPAN>
- With</SPAN> rFound.Interior </SPAN>
- .ColorIndex = 8 </SPAN>
- .Pattern = xlSolid </SPAN>
- .PatternColorIndex = xlAutomatic </SPAN>
- End With</SPAN>
- Set</SPAN> rFound = .FindNext(rFound) </SPAN>
- Loop</SPAN> While</SPAN> Not</SPAN> rFound </SPAN>Is</SPAN> Nothing</SPAN> And</SPAN> rFound.Address <> strFirstAdd </SPAN>
- End</SPAN> If</SPAN>
- End With</SPAN>
- End Sub</SPAN>
Last edited: