Hello All,
I am trying to create a counter for colored cells by a specific color (red), that looks at conditional formatting colors rather than the standard fill color option.
Method: 1 file - Condition_Formatting
I am trying to count only the red cells in my document in every column where they will appear. I am using conditional formatting to fill cells where people are late = red fill color.
that works fine.
My problem is I need each column to have the total count by their respective name headers in row 1.
I need to modify this code, so that I can populate the total, for all cells containing fill color red in each column. The current script display's a msgbox, but I need it to run and append the count to each column.
Method 2 file- Color Counter
I have a second method that uses (UDF) and it works, but I have to adjust the calculations on the formula bar to manual instead of automatic and then I get the proper count for each red cell. I am think that a loop would need to be created each column that I would need to do a count total. I am not a expert on loops, but if someone could look at both methods and maybe fine a better way of doing this.
I am trying to create a counter for colored cells by a specific color (red), that looks at conditional formatting colors rather than the standard fill color option.
Method: 1 file - Condition_Formatting
I am trying to count only the red cells in my document in every column where they will appear. I am using conditional formatting to fill cells where people are late = red fill color.
that works fine.
My problem is I need each column to have the total count by their respective name headers in row 1.
I need to modify this code, so that I can populate the total, for all cells containing fill color red in each column. The current script display's a msgbox, but I need it to run and append the count to each column.
Code:
Sub SumCountByConditionalFormat()
Dim indRefColor As Long
Dim cellCurrent As Range
Dim cntRes As Long
Dim cntCells As Long
Dim indCurCell As Long
cntRes = 0
cntCells = Selection.CountLarge
indRefColor = ActiveCell.DisplayFormat.Interior.Color
For indCurCell = 1 To (cntCells - 1)
If indRefColor = Selection(indCurCell).DisplayFormat.Interior.Color Then
cntRes = cntRes + 1
End If
Next
MsgBox "Count=" & cntRes & vbCrLf & vbCrLf & _
"Color=" & Left("000000", 6 - Len(Hex(indRefColor))) & _
Hex(indRefColor) & vbCrLf, , "Count by Conditional Format color"
End Sub
Method 2 file- Color Counter
I have a second method that uses (UDF) and it works, but I have to adjust the calculations on the formula bar to manual instead of automatic and then I get the proper count for each red cell. I am think that a loop would need to be created each column that I would need to do a count total. I am not a expert on loops, but if someone could look at both methods and maybe fine a better way of doing this.
Code:
Function CountColorIf(rSample As Range, rArea As Range) As Long
Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long
lMatchColor = rSample.DisplayFormat.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.DisplayFormat.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
End If
Next rAreaCell
CountColorIf = lCounter
End Function
Sub CountColorIf2()
Dim rSample As Range
Dim rArea As Range
Dim rAreaCell As Range
Dim lMatchColor As Long
Dim lCounter As Long
Dim CC As Long
Set rSample = Range("b12")
Set rArea = Range("c5:c6")
lMatchColor = rSample.DisplayFormat.Interior.Color
For Each rAreaCell In rArea
If rAreaCell.DisplayFormat.Interior.Color = lMatchColor Then
lCounter = lCounter + 1
End If
Next rAreaCell
CC = lCounter
End Sub