Add together Values in Coloured Cells

jamieleeuk

Board Regular
Joined
Feb 9, 2009
Messages
99
Hi,

I have had a look through some searches and I can't find any that have answered this question before so would appreciate it if someone could assist.

I have a few cells on a sheet which will be coloured red. They won't always be the same cell references, but they will always be the same colour.

I was wondering if there was some VBA code somewhere which would allow me to put in cell D1 the total amount of the coloured cells.

Please, if you need more info, just ask'

Kind Regards
Jamie
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Use this code in a module.

Code:
Function CountColour(CellRng As Range, CellColInd As Range)

    Dim i As Double
    Dim ColInd As Double
    Dim rCell As Range
     
    Application.Volatile
    
    i = 0
    
    ColInd = CellColInd.Interior.ColorIndex
    
    For Each rCell In CellRng
    
        If rCell.Interior.ColorIndex = ColInd Then
        
            i = i + 1
            
        End If
    
    Next rCell
    
    CountColour = i
    
End Function

Use it as follows:

=CountColour(YourDataRange,ReferenceOfTheColouredCell)


for example, if your data is in A1:A100 and A1 is red then

=CountColour(A1:A100,A1)

This has the added advantage in that you can use it to count not just red cells, but any coloured cells.

Hope this helps.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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