VBA macro Help-plzzzzzzzzzzzzzzzzzzzzzz

windows , VBA , MS Excel India
  • 11 years ago

    Hi My question is "how to count the cells which satisfying the given conditional formatting?" eg. If my Conditional formatting is "greater than 5",so after setting these formatting the color of cell's which satisfying the condition will get change. So i want a macro which can do it dynamically.

    Nitesh Thanx & Regards

  • 11 years ago

    Hi My question is "how to count the cells which satisfying the given conditional formatting?" eg. If my Conditional formatting is "greater than 5",so after setting these formatting the color of cell's which satisfying the condition will get change. So i want a macro which can do it dynamically.

    Nitesh Thanx & Regards

  • 11 years ago

    Here's a macro that will count the number of cells in range E1:E10 that have the "greater than 5" condition for conditional formatting:

    Sub CountConditionals()
    Dim i As Integer
    Dim intCells As Integer
    Dim strFormat As String
    For i = 1 To 10
        On Error Resume Next
        With Range("E" & i).FormatConditions(1)
        'An error is generated if there is no conditional formatting, so see if an error occurs:
            If IsError(.Operator > 0) Then
                'do nothing
            ElseIf .Operator = xlGreater And .Formula1 = "5" Then
                intCells = intCells + 1
            End If
        End With
    Next i
    MsgBox "There are " & intCells & " cells with the '> 5' conditional format."
    
    End Sub
    

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Owning a computer without programming is like having a kitchen and using only the microwave oven” - Charles Petzold