Hi,
I found a VBA code that counts how many coloured cells I have..but I cannot seem to make it work (see attached file). I added the module and typed in the formula...but it is not returning the value. I have attached the sheet.
I am looking to count how many of three different colours appears in column B and the % it comes up. Can someone let me know what I am doing wrong?
The code I used is:
![]()
Option Explicit '''This is for counting the number of filled cells within a Range 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
Bookmarks