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

preview_player
Показать описание
Excel VBA Macro: Count and List the Number of (Conditonally Formatted) Cells at the End of Each Row

This is a modification of code from:

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
Рекомендации по теме
Комментарии
Автор

I used lo do for loop for this kind of procedure, but now I prefer to use Do Until... i.e. Do Until Range("A" & i)="", then eliminate one extra variable like row_count.

kameya
Автор

I have 1 year data but how to Filter one month data automatically Using VBA paste to new sheet

coolvideos