How to calculate number of rows containing any colored cells?

Hol_dav

New Member
Joined
Jan 26, 2023
Messages
22
Office Version
  1. 365
Platform
  1. Windows
I am wondering if there is a VBA/macro that I can run to count the number of rows in my table that contain any colored cells?

My research seems to only turn up code for counting colored cells, but I need to count the entire row as 1, regardless of how many or what color cells are contained.

Please help me!
 
well, that's only half way through. Then you need to insert the vba that others have posted to count your colored cells.
And speaking of that. You may want to test all the color counting on a just a few rows. You need to make sure the color index number (If that is what it is called) can be recognized. If not you need to experiment and find out which colors to use.

But, now that you have these rules you can use them to create a count of errors per row and sum them.
Absolutely - this is brilliant, thank you Awoohaw!!
 
Upvote 0

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
See if this macro does what you want...
VBA Code:
Sub CountRowsWithColor()
  Dim Cnt As Long, Rng As Range
  For Each Rng In ActiveSheet.UsedRange.Rows
    Cnt = Cnt - (Rng.Interior.Color = 0)
  Next
  MsgBox "There are " & Cnt & " colored rows."
End Sub
Hi Rick - I have been applying my conditional formatting and at some point have messed up the macro you created? I tried deleting and adding back in but it still isn't working. When I run the macro, I get the wrong answer now... what might I have done wrong to change the outcome of the macro?

When I run the macro in another workbook, it seems to compute correctly though. Any advice would be appreciated!
 
Upvote 0
Hi Rick - I have been applying my conditional formatting and at some point have messed up the macro you created? I tried deleting and adding back in but it still isn't working. When I run the macro, I get the wrong answer now... what might I have done wrong to change the outcome of the macro?

When I run the macro in another workbook, it seems to compute correctly though. Any advice would be appreciated!
@Rick Rothstein, seems like the macro works to identify manually formatted cells? Is there anything I can change so that it recognizes conditionally formatted cells and counts those rows?
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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