我有一个函数 FILTER_COL 应该过滤范围 rng 中的单元格,这些单元格与 from_cell 的单元格颜色相同:
Function FILTER_COL(from_cell As String, rng As Range)
Dim colour As Integer
For Each cell In Range(from_cell)
colour = cell.Interior.ColorIndex
Next cell
Dim Out As Variant
For Each cell In rng
If cell.Interior.ColorIndex = colour Then
Out.Add (cell.Value)
End If
Next cell
FILTER_COL = Out
End Function
然后我将结果放入 SUM 中,如下所示:
SUM(FILTER_COL("A55",K50:K52))
它给出了一个#VALUE!如果 K50:K52 范围内有任何与 A55 颜色相同的单元格,则会出错。