简体   繁体   中英

VBA checking cell interior color

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM