count conditional formatted highlighted cells

ziyan89

New Member
Joined
Dec 19, 2015
Messages
32
Hi,

May i ask how do I count the number of conditional formatted highlighted cells across the row
Please note each row has cells with different colour as different criteria highlight different colour. I need to know the number of cells highlighted with each colour across each row

Try VBA but cannot work
PHP:
Function CountCFCells(rng As Range, C As Range)Dim i As Single, j As Long, k As LongDim chk As Boolean, Str1 As String, CFCELL As Rangechk = FalseFor i = 1 To rng.FormatConditions.Count    If rng.FormatConditions(i).Interior.ColorIndex = C.Interior.ColorIndex Then        chk = True        Exit For    End IfNext ij = 0k = 0If 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 CFCELLElseCountCFCells = "Color not found"Exit FunctionEnd IfCountCFCells = jEnd Function


Tried this VBA also did not work
PHP:
Function CountCFCells(Rng As Range, ColorIndex As Long) As Long    Dim I&, J&, Tmp$, Str1$    Dim CfCell As Range    Dim FC As FormatCondition, IIFlg As Boolean        For Each FC In Rng.FormatConditions        If FC.Interior.ColorIndex = ColorIndex Then Exit For    Next FC        If FC Is Nothing Then Exit Function        Str1 = FC.Formula1    For I = 1 To Len(Str1)        Tmp = Mid(Str1, I, 1)        If ("0123456789" Like "*" & Tmp & "*") Then            IIFlg = True        Else            If IIFlg Then Exit For        End If    Next I        Tmp = Right(Str1, Len(Str1) - I + 1)        For Each CfCell In Rng        Str1 = "=" & CfCell.Address & Tmp        If Rng.Worksheet.Evaluate(Str1) = True Then J = J + 1    Next CfCell        CountCFCells = JEnd Function
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It's FAR easier to count the condition, not the formatted result.

If your conditional formatting is say Greater than 10
Then count how many cells are greater than 10

=COUNTIF(A1:A10,">10")
 
Upvote 0
Hi thank you for the suggestion, however it is not possible as I have more than 50 conditions each resulting in different colours
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,362
Members
449,155
Latest member
ravioli44

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