VBA code count based on CONDITIONAL FORMATTING CELLS

caos88

Board Regular
Joined
Mar 12, 2020
Messages
66
Office Version
  1. 2010
Platform
  1. Windows
Hello everyone,

i wish to count date in column E according to 2 conditional formatting colors. Do you know if vba is possible for it ? or maybe a COUNTIF formula is more effective ?

Thank you
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this, you will need to edit the colors in the code.

To find the conditional format color to place in the code you can select one of the colored cells and run the below code.

VBA Code:
Sub GetCFcolor()
x = ActiveCell.DisplayFormat.Interior.Color
MsgBox x
End Sub

The code to count the conditional formated colors.
VBA Code:
Sub CountCF1()
    Dim sh As Worksheet, x As Long, rng As Range, c As Range
    Set sh = ActiveSheet
    Set rng = sh.Columns("E:E").SpecialCells(xlCellTypeAllFormatConditions)
    For Each c In rng.Cells
        If c.DisplayFormat.Interior.Color = 5287936 Or _
           c.DisplayFormat.Interior.Color = 255 Then
            x = x + 1
        End If
    Next c
    MsgBox x

End Sub

1601814131442.png
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,264
Members
449,075
Latest member
staticfluids

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