I have macro that is to reference a list of word on a worksheet ("List")and then check for the list in a another worksheet ("sheet 1"). If a word is present in the list then certain formatting will be done to columns A:E of the sheet 1 worksheet. The macro partially works, except it fills the entire columns A:E in my sheet 1 worksheet. I am not a vba expert, I tried to join all the cells and separate with a "|" then use the InStr function to return a value or a 0. Can someone please provide advice on why this is not working correctly. Here is the code:
Public Sub HighlightListedValues()
Dim strConcatList As String
Dim Cell As Range
'Creates a string concatenating list of strings, separated by |s
'e.g. "item1|item2|item3|item4|"
For Each Cell In Sheets("List").Range("A1:A10")
strConcatList = strConcatList & Cell.Value & "|"
Next Cell
'For each used cell in Column A of sheet1, check whether the value in that cell
'is contained within the concatenated string
For Each Cell In Intersect(Sheets("Sheet1").Range("A:A"), Sheets("Sheet1").UsedRange)
If InStr(strConcatList, Cell.Value) > 0 Then 'InStr returns 0 if the string isn't found
Cell.Columns("A:E").Interior.Color = RGB(0, 0, 128) 'Highlights the row in blue if value found
Cell.Columns("A:E").Font.Color = RGB(255, 255, 255) 'Highlights the font in white if value found
Cell.Columns("A:E").Font.Bold = True 'Bolds the font
End If
Next Cell
End Sub
Public Sub HighlightListedValues()
Dim strConcatList As String
Dim Cell As Range
'Creates a string concatenating list of strings, separated by |s
'e.g. "item1|item2|item3|item4|"
For Each Cell In Sheets("List").Range("A1:A10")
strConcatList = strConcatList & Cell.Value & "|"
Next Cell
'For each used cell in Column A of sheet1, check whether the value in that cell
'is contained within the concatenated string
For Each Cell In Intersect(Sheets("Sheet1").Range("A:A"), Sheets("Sheet1").UsedRange)
If InStr(strConcatList, Cell.Value) > 0 Then 'InStr returns 0 if the string isn't found
Cell.Columns("A:E").Interior.Color = RGB(0, 0, 128) 'Highlights the row in blue if value found
Cell.Columns("A:E").Font.Color = RGB(255, 255, 255) 'Highlights the font in white if value found
Cell.Columns("A:E").Font.Bold = True 'Bolds the font
End If
Next Cell
End Sub