Forum Discussion
Seaweedfarm
Sep 28, 2023Copper Contributor
Help with an Excel formula
Hi all, I was wondering if anyone can solve this problem please. I am trying to get a formula that will add something like the following cells: The formula needs to add the numbers depending...
HansVogelaar
Oct 02, 2023MVP
Assuming that the colours have been applied directly, you'll need a custom VBA function:
Function SumByColor(DataRange As Range, ColorCell As Range) As Double
Dim Cell As Range
Dim Parts() As String
Application.Volatile
For Each Cell In DataRange
If Cell.Interior.Color = ColorCell.Interior.Color Then
Parts = Split(Cell.Value)
On Error Resume Next
SumByColor = SumByColor + Parts(1)
On Error GoTo 0
End If
Next Cell
End Function
Use as in the screenshot:
The attached demo workbook is a macro-enabled workbook, so make sure that you allow macros when you open it.
Seaweedfarm
Oct 03, 2023Copper Contributor
Thank you HansVogelaar. That has worked perfectly!