How can I count True Conditional Formating?

USAMax

Well-known Member
Joined
May 31, 2006
Messages
846
Office Version
  1. 365
Platform
  1. Windows
There are so many articles on this and I have spent hours going through them. One returns the color of the Conditional Formatting and is so long just to find if it the conditions have been meet or not!

I found this one that should work but it fails at the Evaluate function.

Code:
Function CountCFCells(rng As Range)
Dim i As Single, j As Long
Dim chk As Boolean, Str1 As String, CFCELL As Range
chk = False
For i = 1 To rng.FormatConditions.Count
    Test1 = rng.FormatConditions(i).Interior.ColorIndex
    If rng.FormatConditions(i).Interior.ColorIndex = 65535 Or _
       rng.FormatConditions(i).Interior.ColorIndex = 6 Then
        chk = True
        Exit For
    End If
Next i
j = 0
If chk = True Then
    For Each CFCELL In rng
        If CFCELL.FormatConditions.Count Then
            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
        End If
    Next CFCELL
Else
CountCFCells = "Color not found"
Exit Function
End If
CountCFCells = j
End Function

The conditional formula is:

=AND(NOT(ISBLANK(RC2)), ISBLANK(RC))

I have always loved Excel but this is pissing me off. Anybody please....
 

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
What is the i in this line? (Inside the If chk = True, For Each CFCELL in rng loop) Should it be a 1?
Code:
Str1 = CFCELL.FormatConditions(i).Formula1
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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