Count conditionally colored cells

harieta

New Member
Joined
Mar 16, 2023
Messages
27
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,
I've been trying to count cells by row which have been conditionally coloured
There are 3 rules for each cell
c3<=b19 is green
c3>b19 is red
when c3 is blank no formatting.
I used the UDF posted here but the count is incorrect. where do i go wrong?

Function COUNTConditionColorCells(CellsRange As Range, ColorRng As Range)
Dim Bambo As Boolean
Dim dbw As String
Dim CFCELL As Range
Dim CF1 As Single
Dim CF2 As Double
Dim CF3 As Long
Bambo = False
For CF1 = 1 To CellsRange.FormatConditions.Count
If CellsRange.FormatConditions(CF1).Interior.ColorIndex = ColorRng.Interior.ColorIndex Then
Bambo = True
Exit For
End If
Next CF1
CF2 = 0
CF3 = 0
If Bambo = True Then
For Each CFCELL In CellsRange
dbw = CFCELL.FormatConditions(CF1).Formula1
dbw = Application.ConvertFormula(dbw, xlA1, xlR1C1)
dbw = Application.ConvertFormula(dbw, xlR1C1, xlA1, , ActiveCell.Resize(CellsRange.Rows.Count, CellsRange.Columns.Count).Cells(CF3 + 1))
If Evaluate(dbw) = True Then CF2 = CF2 + 1
CF3 = CF3 + 1
Next CFCELL
Else
COUNTConditionColorCells = "NO-COLOR"
Exit Function
End If
COUNTConditionColorCells = CF2
End Function
 

Attachments

  • 2023-03-21_15-54-53.jpg
    2023-03-21_15-54-53.jpg
    13 KB · Views: 16

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Why not simply use same rules you used in your Conditional Formatting in a COUNTIF (or COUNTIFS) formula to count up the cells meeting those conditions?
 
Upvote 0
Why not simply use same rules you used in your Conditional Formatting in a COUNTIF (or COUNTIFS) formula to count up the cells meeting those conditions?
Not sure if that will work, as each cell is formatted in relation to different date. For example cell c3 will have date 17th of Jan and be green, but cell d3 will have same date but coloured red (deadlines for each cell is different)
 
Upvote 0
Can you show us a larger sample size (more than one row) so we can get a better idea of how these rules work?
Be sure to include row numbers and column letters in your image so we can see exactly where all the data resides on your sheet.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
Can you show us a larger sample size (more than one row) so we can get a better idea of how these rules work?
Be sure to include row numbers and column letters in your image so we can see exactly where all the data resides on your sheet.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
sample.xlsx
ABCDEFGH
1123456
224-Jan 11:0017-Jan 11:1713-Jan 13:2317-Jan 11:48
322-Feb 17:2316-Feb 14:2120-Feb 17:4720-Feb 21:27
415-Mar 14:1620-Mar 12:1120-Mar 13:59
5
6
7
8
9
10
11
12
13
14
15
16deadline1deadline 2deadline 3deadline 4deadline 5deadline 6
17
1817-Jan20-Jan17-Jan24-Jan24-Jan27-Jan
1921-Feb21-Feb16-Feb23-Feb21-Feb24-Feb
2021-Mar21-Mar15-Mar23-Mar21-Mar28-Mar
2119-Apr20-Apr18-Apr25-Apr25-Apr25-Apr
2219-May22-May16-May23-May23-May25-May
2320-Jun20-Jun16-Jun23-Jun27-Jun27-Jun
2419-Jul20-Jul18-Jul25-Jul25-Jul27-Jul
2521-Aug22-Aug16-Aug22-Aug22-Aug29-Aug
2619-Sep20-Sep18-Sep25-Sep26-Sep26-Sep
2719-Oct20-Oct17-Oct24-Oct24-Oct27-Oct
2821-Nov21-Nov16-Nov23-Nov21-Nov28-Nov
2912-Dec14-Dec13-Dec18-Dec14-Dec22-Dec
30
31
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
F2:F13Expression=$F2=""textYES
F2:F13Expression=$F2>$G18textNO
F2:F13Expression=$F2<=$G18textNO
E2:E13Expression=$E2=""textYES
E2:E13Expression=$E2>$F18textNO
E2:E13Expression=$E2<=$F18textNO
D2:D13Expression=$D2=""textYES
D2:D13Expression=$D2>$E18textNO
D2:D13Expression=$D2<=$E$18textNO
C2:C13Expression=$C2=""textYES
C2:C13Expression=$C2>$D18textNO
C2:C13Expression=$C2<=$D18textNO
B2:B13Expression=$B2=""textYES
B2:B13Expression=$B2>$C18textNO
B2:B13Expression=$B$2<=C$18textNO
A2:A13Expression=$A2=""textYES
A2:A13Expression=$A2>$B$18textNO
A2:A13Expression=$A2<=$B$18textNO


I've attached mini sheet with all formatting
 
Upvote 0
I see. I didn't realize that there isn't a consistency to your Conditional Formatting formulas, and you actually have a bunch of formulas doing different things returning the same color.

There are lots of threads on the internet that will show you how you can count cells colored by Conditional Formatting.
Here is one, you can find many others with a simple Google search.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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