Count conditional formatting

Bradzo

New Member
Joined
Nov 15, 2017
Messages
11
Hi Everyone,

I sometime ago made a spreadsheet with the below Marco to count the conditional formatted cells in a set row. I now I need to amend the sheet to have it run in all the rows below and I can't work out hoe to adapt the code. Each attempt has resulted in failure and I'm reaching out for assistance.

I would like to continue down the the original range of P9:AK9 to P10:AK10 and so on until P45:AK45 and return each row result into AL9: to AL45.

Thanks, Brad


CountColorCells()
Dim rng As Range
Dim lColorCounter As Long
Dim rngCell As Range
'Set the range
Set rng = ("Site SOP Sign-off").Range("P9:AK9")
For Each rngCell In rng
If Cells(rngCell.Row, rngCell.Column).DisplayFormat.Interior.Color = RGB(0, 176, 80) Then
lColorCounter = lColorCounter + 1
End If
Next
Sheets.("Site SOP Sign-off").Range("AL9") = lColorCounter
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hello there. I have corrected a couple of typos, and added the loop you want whilst keeping as much of your code unchanged as possible.
VBA Code:
Sub CountColorCells()
    Dim rng As Range
    Dim lColorCounter As Long
    Dim rngCell As Range
    Dim NextLine As Long
'Set the range
    For NextLine = 9 To 45
        lColorCounter = 0
        Set rng = Sheets("Site SOP Sign-off").Range("P" & NextLine & ":AK" & NextLine)
        For Each rngCell In rng
            If Cells(rngCell.Row, rngCell.Column).DisplayFormat.Interior.Color = RGB(0, 176, 80) Then
                lColorCounter = lColorCounter + 1
            End If
        Next rngCell
        Sheets("Site SOP Sign-off").Range("AL" & NextLine) = lColorCounter
    Next NextLine
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,750
Messages
6,126,666
Members
449,326
Latest member
asp123

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