Can someone help me create a macro that will search an Excel worksheet for a list of 30 strings (e.g., SV-32488r1
, SV-33485r1
) and highlight the Row
when found?
Thank you so much in advance.
Public Sub HighlightListedValues()
Dim strConcatList As String
Dim cell As Range
'Creates a string concatenating your list of strings, separated by |s
'e.g. "item1|item2|item3|item4|"
For Each cell In Sheets("List").Range("A1:A30")
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.EntireRow.Interior.Color = RGB(255, 0, 0) 'Highlights the row in red if value found
End If
Next cell
End Sub
This will highlight the relevant rows in red if the following is true:
Amend the names of worksheets and ranges as needed e.g. If you want to search in Columns A to C of a worksheet named "Data" you would amend Sheets("Sheet1").Range("A:A")
to Sheets("Data").Range("A:C")
Hope this helps!