Adding time worked in excel

bucci35

Active Member
Joined
Jul 6, 2002
Messages
352
Office Version
  1. 365
Platform
  1. Windows
Hello,
Considering the cells below are in the following order of color. (green, green, red, red, yellow) I need to be able to sum the colors separately. Any ideas? TIA!
A B C D E
54138
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
You'd need VBA. Is that what you're looking?
Is there a rule for determining the color?
 
Upvote 0
Using hex code is the most reliable instead "green", "red", ect...
The VBA function takes in a range, and a hex string (indicate which color).
VBA Code:
Function SumByHexColor(CellRange As Range, hexColor As String) As Double
    Dim cell As Range
    Dim totalSum As Double
    Dim colorValue As Long
    
        
    Application.Volatile
    If Left(hexColor, 1) = "#" Then hexColor = Mid(hexColor, 2)
    colorValue = CLng("&H" & Right(hexColor, 6))
    
    For Each cell In CellRange
        If cell.Interior.Color = colorValue Then
            If IsNumeric(cell.Value) Then
                totalSum = totalSum + cell.Value
            End If
        End If
    Next cell

    SumByHexColor = totalSum

End Function

Usage:
Book1
ABCDE
154138
2
3ColorHex#Sum
4Green#00FA009
5Red#0026FF4
6Yellow#00FFFF8
Sheet1
Cell Formulas
RangeFormula
C4:C6C4=SumByHexColor($A$1:$E$1,B4)
 
Upvote 0

Forum statistics

Threads
1,225,749
Messages
6,186,802
Members
453,373
Latest member
Ereha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top