conditional format color count

HAASEWM

New Member
Joined
Jul 11, 2016
Messages
1
I'm using excel 2013.
How do I count the number of cells that have been conditionally formatted to be a certain color and output the result in another cell?

I have a spreadsheet full of stock picks.
All stocks are displayed in rows 5-50
Different analysts ratings are displayed in columns F thru S.
cells F5:S50 are conditionally formatted.
If analyst rates buy, the cell turns green
If analyst rates hold, the cell turns yellow
If analyst rate sell, the cell turns red

column T displays the number of buy ratings
column U displays the number of hold ratings
column V displays the number of sell ratings

cell T5 should display the number of cells in f5:s5 that have been conditionally formatted to be green

t6 should display # of greens from f6:s6

etc.

I tried a few downloads that let me count colored cells (ASAP utilities) but for some reason it doesn't work on conditionally formatted cells

I tried some VBA code I found online:
Function CountCFCells(rng As Range, C As Range)
Dim i As Single, j As Long, k As Long
Dim chk As Boolean, Str1 As String, CFCELL As Range
chk = False
For i = 1 To rng.FormatConditions.Count
If rng.FormatConditions(i).Interior.ColorIndex = C.Interior.ColorIndex Then
chk = True
Exit For
End If
Next i
j = 0
k = 0
If chk = True Then
For Each CFCELL In rng
Str1 = CFCELL.FormatConditions(i).Formula1
Str1 = Application.ConvertFormula(Str1, xlA1, xlR1C1)
Str1 = Application.ConvertFormula(Str1, xlR1C1, xlA1, , ActiveCell.Resize(rng.Rows.Count, rng.Columns.Count).Cells(k + 1))
If Evaluate(Str1) = True Then j = j + 1
k = k + 1
Next CFCELL
Else
CountCFCells = "Color not found"
Exit Function
End If
CountCFCells = j
End Function

I can't get it to work - I read someone said it only works for excel 2010.
I'm banging my head against a wall on this one. Someone please tell me this is easy and explain to me how to do it. (I'm not too bright, take that into account ;))

thx!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
A conditional format requires to meat a certain condition to change the format of a cell. This means that you should be able to count the conditional formatted cells with an =SUMIFS() or =SUMPRODUCT() formula.

Just keep it simple.
 
Upvote 0

Forum statistics

Threads
1,215,330
Messages
6,124,308
Members
449,152
Latest member
PressEscape

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