Formula dependent of cell colour

Kiwi den

Board Regular
Joined
Feb 17, 2014
Messages
143
Office Version
  1. 365
Platform
  1. Windows
Looking for assistance
I have a spreadsheet with column H from cells 1 - 750 populated by numbers.
I would like to total the cells in this column into cell (H:751) that have a cell colour "Green"

Can someone please point me for info on how I could do this please
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How are the cells being coloured?
 
Upvote 0
In that case you will need VBA, a formula cannot see cell formats.
 
Upvote 0
How about
VBA Code:
Function SumByColor(SumRange As Range, ColourCell As Range) As Double
   Dim Cl As Range
   Dim Colr As Long
   Application.Volatile
   
   Colr = ColourCell.Interior.Color
   For Each Cl In SumRange
      If Cl.Interior.Color = Colr Then
         SumByColor = SumByColor + Cl.Value
      End If
   Next TCell
End Function
Used like
Excel Formula:
=SumByColor(H1:H170,G1)
where H1:H170 is the range to sum & G1 has the colour you're interested in.
However this will only recalculate when the sheet recalcs & not when you change the colour of a cell.
 
Upvote 0
How about
VBA Code:
Function SumByColor(SumRange As Range, ColourCell As Range) As Double
   Dim Cl As Range
   Dim Colr As Long
   Application.Volatile
  
   Colr = ColourCell.Interior.Color
   For Each Cl In SumRange
      If Cl.Interior.Color = Colr Then
         SumByColor = SumByColor + Cl.Value
      End If
   Next TCell
End Function
Used like
Excel Formula:
=SumByColor(H1:H170,G1)
where H1:H170 is the range to sum & G1 has the colour you're interested in.
However this will only recalculate when the sheet recalcs & not when you change the colour of a cell.
Thanks I will give this a try
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,428
Members
448,896
Latest member
MadMarty

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