2016-08-21 217 views
0

我想根据单元格的内部颜色做一些事情。VBA检查单元格内部颜色

这是迄今为止的代码,但它在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 

如果您有任何想法,将不胜感激。谢谢

+0

工作尝试改变'如果.Range( “A”,I).Interior.ColorIndex = 4 Then'为'如果。范围(“A”,i).Interior.Color = 4然后' –

+0

这不起作用。 – Smithfield

+0

错误是“错误'1004':应用程序定义的或对象定义的错误” – Smithfield

回答

1

作为替代该版本可能是有点更容易

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

你不能合并范围内的字母和数字。改用单元格。您需要将细胞放入细胞两次,因为使用cells来填充细胞时需要使用Range。
Range(Cells(i, 1), Cells(i, 1)).Interior.ColorIndex