仅当单元格是特定颜色时才执行Excel公式

时间:2015-08-10 17:08:25

标签: excel vba excel-vba

我在"摘要"中有以下公式。工作表从单元格F4开始:F13 ......

=COUNTIFS('Master Matrix'!L:L,A4,'Master Matrix'!M:M,"Received")

当然" A4"在公式中更改为" A5"当公式在F5等时

我想要的是......

=IF(mycolor<>16,COUNTIFS('Master Matrix'!L:L,A4,'Master Matrix'!M:M,"Received"))

&#34;&mycolor LT;&GT; 16&#34;应该是指背景颜色不是&#34;颜色16&#34;,灰色,#808080或RGB 128,128,128,然后执行COUNTIFS。

有人可以帮我解决这个问题吗?我是否需要VBA功能和\或命名范围才能使其正常工作?

1 个答案:

答案 0 :(得分:0)

如果您不想做太多VBA,可以创建自定义功能。以下函数可在电子表格中调用并采用两个参数。第一个参数是颜色索引,第二个参数是您要引用的单元格。)

将其添加到工作簿中的新模块,它应该可用于整个工作簿。

Public Function IsCellColor(ByVal ColorIndex As Integer, Optional ByRef Reference As Range)

    If Reference Is Nothing Then Set Reference = ActiveCell

    If Reference.Interior.ColorIndex = ColorIndex Then
        IsCellColor = True
    Else
        IsCellColor = False
    End If

End Function