0
votes

I am trying to do something depending on the interior color of a cell.

This is my code so far but it is showing errors on the If line.

For i = 3 To dumpLastRow
With masterFile.Sheets(dumpRef)

    If .Range("A", i).Interior.ColorIndex = 4 Then
            ''''CODE''''
    Else
            ''''CODE''''
    End If

End With
Next

If you have any idea it would be appreciated. Thanks

2
try changing If .Range("A", i).Interior.ColorIndex = 4 Then to If .Range("A", i).Interior.Color = 4 Then - Shai Rado
This still doesn't work unfortunately. - Smithfield
The error is "error '1004': Application defined or object defined error" - Smithfield
What shall .Range("A", i)be? Where is it documented? Either .Range("A" & i) or .Cells(i, "A") can be used. - Axel Richter
stupid error, meant change to If .Range("A" & i).Interior.ColorIndex = 4 Then - Shai Rado

2 Answers

1
votes

as alternative this version might be a bit easier to work with

With masterFile.Sheets(dumpRef)
    Dim cell As Range

    For Each cell In .Range("A3:A" & dumpLastRow).Cells

        If cell.Interior.ColorIndex = 4 Then
            ''''CODE''''
        Else
            ''''CODE''''
        End If
    Next
End With
0
votes

You cannot combine letters and numbers like that in range. Use cells instead. You will need to put in cells twice as Range requires that when using cells to populate it.
Range(Cells(i, 1), Cells(i, 1)).Interior.ColorIndex