I am trying to turn the font to red for the occurrences of a list of words in excel. So far, I am able to find a single word, but I need to search for a whole array. I am a newbie with VBA and struggling. So far, I've been able to find this as a solution, but it deals with finding a single string, "F1":
Sub test4String2color()
Dim strTest As String
Dim strLen As Integer
strTest = Range("F1")
For Each cell In Range("A1:D100")
If InStr(cell, strTest) > 0 Then
cell.Characters(InStr(cell, strTest), strLen).Font.Color = vbRed
End If
Next
End Sub
Edit:
The cells I need highlighted have the items listed in comma separated format. For example, "Apple 1, Apple 3, Banana 4, Orange". The list of values to search from are in Different cells, "Apple", "Banana 4". I only want to highlight "Banana 4" because this is an EXACT match with the comma separated values. In the current formulation, the text that says "Apple 1" or "Apple 4" would be partially highlighted.
Edit 2:
This is the actual format from my workbook:
Gotham
inF1
, it correctly highlights any finding ofGotham
in the rangeA1:D100
(it highlights "Gotham" and all text after in the cell). Are you saying thatF1
could have, sayGotham, City, Wayne Enterprises
, and you want to search for each one of those words (separated by a comma, or some other delimiter)? – BruceWaynestrTest
a Collection and cycle through it for matches with a secondFor Loop
. Since you're not using any UDTs, a collection would be easy to setup and loop through. – Tyeler