Hello all,
Accounting has a requirement in the monthly GL file to flag any items in Column A that has the substring either "lunch", "dinner", "drink" embedded in each item in the cell.
With help of one of the postings in this Forum for a similar question, I came up with below VBA code using the InStr function, Array to store the substrings and 2 loops where I like to highlight the row in Green if it has any of the above substrings in each cell.
But the problem is it's highlighting all the blank rows in Sheet2. Appreciate any help on this. Thank you!
Accounting has a requirement in the monthly GL file to flag any items in Column A that has the substring either "lunch", "dinner", "drink" embedded in each item in the cell.
With help of one of the postings in this Forum for a similar question, I came up with below VBA code using the InStr function, Array to store the substrings and 2 loops where I like to highlight the row in Green if it has any of the above substrings in each cell.
But the problem is it's highlighting all the blank rows in Sheet2. Appreciate any help on this. Thank you!
VBA Code:
Sub Search_list()
Dim CFP_GL As Workbook
Dim cell2 As Range
Dim strConcatList As String
Dim Partial_Text As String
Dim myrange As Range
Dim someArray
Dim arrVal As Variant
Workbooks.Open Filename:="Z:\WIP\CFP GL Jan-Sep 2021-test.xls", UpdateLinks:=False
Set CFP_GL = Application.Workbooks("CFP GL Jan-Sep 2021-test.xls")
Set myrange = CFP_GL.Sheets("Sheet2").Range("A:A")
someArray = Array("dinner", "lunch", "drink")
myrange.Interior.Pattern = xlNone 'This clears all existing colour
For Each cell2 In myrange 'Going through each row in Column A in Sheet 2 of the Workbook
For Each arrVal In someArray
If InStr(arrVal, cell2.Value) <> 0 Then 'InStr should returns 0 if the string isn't found
cell2.EntireRow.Interior.ColorIndex = 4 'Highlights the row in green
End If
Next arrVal
Next cell2
End Sub