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!
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!