基于相邻单元格背景色的Sumif公式

Sumif formula based on background color of adjacent cell

我想知道是否有一个 Sumif 公式可以根据 A 列中它旁边的单元格是否突出显示来对 B 列中的所有值求和。

例如,A3 和 A8 中的单元格突出显示为黄色,因此我希望 B3 和 B8 中的单元格总和进入 F4。是否有我必须创建的公式或宏来完成此操作?

您可以使用 VBA 函数对所有彩色单元格求和:

代码:

Public Function ColorSum(myRange As Range) As Variant

Dim rngCell As Range
Dim total As Variant

For Each rngCell In myRange.Cells

    If rngCell.Interior.ColorIndex <> -4142 Then
    total = total + rngCell.Offset(0, 1).Value
    End If

Next rngCell

ColorSum = total

End Function