Hi,
I have a vba code that is intended to highlight cells based on value of the cell i.e. if it is empty. The code identifies the cell values correctly but it will not colour the cell.
I keep getting an runtime error 9 - Subscript Out of Range Error or runtime 1004 - method 'range of object' worksheet failed.
I have completed other searches and cannot seem to find the solution. As I can clearly see that the cell I am pointing to exists. I have even done a test with a msgbox for that cell and it shows that it exists.
The following is the code. whenever the if statement is met I get the runtime error:
Regards,
Glenn
I have a vba code that is intended to highlight cells based on value of the cell i.e. if it is empty. The code identifies the cell values correctly but it will not colour the cell.
I keep getting an runtime error 9 - Subscript Out of Range Error or runtime 1004 - method 'range of object' worksheet failed.
I have completed other searches and cannot seem to find the solution. As I can clearly see that the cell I am pointing to exists. I have even done a test with a msgbox for that cell and it shows that it exists.
The following is the code. whenever the if statement is met I get the runtime error:
VBA Code:
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "raw data" Or ws.Name = "HP dealer permits" Or ws.Name = "HP harvester permits" Then
'do nothing
Else
lastrow2 = ws.Range("B" & Rows.Count).End(xlUp).Row 'this finds the last row so that this data can be pasted in the same sheets as previous filtered data
For i = 2 To lastrow2
If ws.Range("D" & i).Value = "no match" Then ws.Range(ws.Cells(i, 2), ws.Cells(i, 4)).Interior.ColorIndex = 3
If ws.Range("E" & i).Value = "#NA" Then ws.Range(ws.Cells(i, 5)).Interior.ColorIndex = 3
If ws.Range("J" & i).Value = "No" Then ws.Range(ws.Cells(i, 8), ws.Cells(i, 11)).Interior.ColorIndex = 3
If IsEmpty(ws.Range("L" & i)) = True Then ws.Range(ws.Cells(i, 12)).Interior.ColorIndex = vbRed
If IsEmpty(ws.Range("N" & i)) = True Then ws.Range(ws.Cells(i, 14)).Interior.ColorIndex = 3
Next i
Next ws
End sub
Regards,
Glenn