By rocky48 on Thursday, 07 June 2018
Posted in Excel
Replies 0
Likes 0
Views 2.1K
Votes 0
I have used you very useful Module for counting the number of color filled cells, which works very well.
However, I want to color the cells by Conditionally formating them, and the VBA module does not work in that case.
The spreadsheet I am working on analyses the spend for a commodity per month. The cell is linked to another sheet to show the value for the month.
I guess that you may be able to alter the VBA module, but I am not very conversant with VBA.
Can anyone help to alter the script to accomodate my needs?
Here is the VBA code:
Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
Dim rCell As Range
Dim lCol As Long
Dim vResult
lCol = rColor.Interior.ColorIndex
If SUM = True Then
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = WorksheetFunction.SUM(rCell, vResult)
End If
Next rCell
Else
For Each rCell In rRange
If rCell.Interior.ColorIndex = lCol Then
vResult = 1 + vResult
End If
Next rCell
End If
ColorFunction = vResult
End Function
View Full Post