whitehawk81
Board Regular
- Joined
- Sep 4, 2016
- Messages
- 66
Hi,
I just found an issue concerning the Sumif function. When I enter the ColorIndex as criteria, it gives 0 as result. I tried to enter the formula in many ways, I even setup a ColorIndex function to check if the color index of the cell in criteria is actually the same as for the cells in criteria range. Basically I have a table, where only the cells in the first column have a specific background color. I wanted to sum the other columns based on the background color of the cells in column A.
Here are some of my attempts:
=SUMPRODUCT(--(ColorIndex(DS[DSname])=ColorIndex(A45));DS[MBB])
=SUMIF(DS[DSname];ColorIndex(A71);DS[MBB])
Does anyone have an idea, how this can be done?
I just found an issue concerning the Sumif function. When I enter the ColorIndex as criteria, it gives 0 as result. I tried to enter the formula in many ways, I even setup a ColorIndex function to check if the color index of the cell in criteria is actually the same as for the cells in criteria range. Basically I have a table, where only the cells in the first column have a specific background color. I wanted to sum the other columns based on the background color of the cells in column A.
Here are some of my attempts:
=SUMPRODUCT(--(ColorIndex(DS[DSname])=ColorIndex(A45));DS[MBB])
=SUMIF(DS[DSname];ColorIndex(A71);DS[MBB])
Code:
Function SumifByColor(critRange As Range, CellColor As Range, rRange As Range)Dim cSumif As Long
Dim ColIndex As Integer
ColIndex = CellColor.Interior.ColorIndex
For Each cl In rRange
If critRange.Interior.ColorIndex = ColIndex Then
cSumif = WorksheetFunction.SumIf(critRange, CellColor, rRange)
End If
Next cl
SumifByColor = cSumif
End Function
Does anyone have an idea, how this can be done?