Excel VBA Macro: Count and List the Number of (Conditonally Formatted) Cells at the End of Each Row

Опубликовано: 23 Март 2025
на канале: greggowaffles
1,412
27

Excel VBA Macro: Count and List the Number of (Conditonally Formatted) Cells at the End of Each Row

💥Subscribe:    / @greggowaffles  

This is a modification of code from:
https://www.excelsirji.com/vba-code-c...

Code:
Sub list_cond_cells_per_row()

Dim rng As Range
Dim rngCell As Range
Dim row_count As Integer
Dim col_count As Integer
Dim cond_count As Integer
Dim i As Integer
Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("Sheet1")

ws.Activate
row_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))
col_count = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))

For i = 2 To row_count

Set rng = ws.Range(Cells(i, 1), Cells(i, col_count))
cond_count = 0

For Each rngCell In rng

If Cells(rngCell.Row, rngCell.Column).DisplayFormat. _
Interior.Color = RGB(255, 199, 206) Then
cond_count = cond_count + 1
End If

Next

ws.Cells(i, col_count + 1) = cond_count

Next i

End Sub

#ExcelVBA #ExcelMacro