I get daily reports that have a bunch of grouped tables in several worksheets. There are only certain lines in each table I'm interested in. There is a subset within the value of a cell in each of those lines that determines if it's something I'm interested in or not. That value needs to match the value in a column I have in another sheet. Once I have a match then I can determine which color I want to apply to that line.
I've spent a lot of time on this already, and so far everything I've tried that I could get to run has gotten some of what I want to work, but not all of it. Once I get it working for the first table, I should be able to scale the macro to handle the rest of the workbook.
I started by defining MyList to be the range of cells I want to compare against from the other sheet. Then I set the other variables that I'll eventually be changing when I scale this up. Then I'm removing the existing conditional formatting from the whole workbook since I won't be needing that once I get this all working. Then I activate the worksheet that I want to be working on. The for loop seems to run fine. I have a watch set up for the NB variable, and I can see that update correctly for each loop. The problem I'm running into is that no matter what I do with the IsError(Match()) it never seems to update with each iteration of the for loop. So it either stays at false the entire time and colors every row in the table, or it stays true the entire time and colors nothing (depending on which arrangement of the code I try).
I done a bunch of google searching and reading and can't find the right information to figure out how to fix this. Am I trying to use something in a way that I shouldn't, or am I not defining something correctly? What else am I missing?
I'm new to VBA and haven't really done much of any coding for a number of years. So, in addition to fixing this I'm really interested in the why behind it so I can hopefully not repeat those mistakes.
Set MyList = Worksheets("Sheet1").Range("A1", "A500")
Dim NBcol As Integer, MZcol As Integer, blcol As Integer, NB As String
NBcol = 13
MZcol = 16
blcol = 12
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Cells.FormatConditions.Delete
Next ws
Worksheets("Sheet2").Activate
For i = 7 To 26
NB = Left(Cells(i, NBcol), 6)
If Not IsError(Application.Match(NB, MyList, 0)) Then
If Cells(i, MZcol) >= 3.5 Then
ActiveSheet.Range(Cells(i, blcol), Cells(i, MZcol)).Interior.Color = RGB(250, 191, 143)
Else
ActiveSheet.Range(Cells(i, blcol), Cells(i, MZcol)).Interior.Color = RGB(197, 217, 241)
End If
Else
End If
Next i