[英]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. 到目前为止,这是我的代码,但是在If行上显示错误。
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
进行填充时要求的。
Range(Cells(i, 1), Cells(i, 1)).Interior.ColorIndex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.