Couple of things
- You are using the
ws
object before initializing it.
- Since you want to change it to white, I guess you want
2
instead of 1
?
Is this what you are trying?
Option Explicit
Sub Change_Row_Color()
Dim ws As Worksheet
Dim rng As Range
Dim i As Long, j As Long
Set ws = ThisWorkbook.Sheets("Job Card Master")
Set rng = ws.Range("A13:Q299")
With ws
For i = 1 To rng.Rows.Count
For j = 1 To rng.Columns.Count
If rng.Cells(i, j).Interior.ColorIndex = 4 Then
.Range(rng.Cells(i, 1), rng.Cells(i, 17)).Interior.Pattern = xlNone
Exit For
End If
Next j
Next i
End With
End Sub
To change the color of the entire row and not just A
to Q
, change the line
.Range(rng.Cells(i, 1), rng.Cells(i, 17)).Interior.ColorIndex = 2
to
.Rows(rng.Cells(i, 1).Row).Interior.ColorIndex = 2
NOTE:
Remember, White
doesn't mean No Fill
. If you are trying to remove the color then try this
.Interior.Pattern = xlNone
instead of
.Interior.ColorIndex = 2
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…