I am trying to create a custom function (to count the number of cells in a range that have font color = red). I have the code to do this, so that's not my problem. My problem is that having created the function, saved the VBA screen when I go back to the spreadsheet and type "=countcolorif(" the function is just not in the list and if I persist in trying to complete the syntax, I just get "#NAME" error. What's going on?
I googled this a lot and watched YouTube videos but the function still refuses to show in-cell. It is in the user-defined list when I select "Insert Function" on the Formulas ribbon but I do not want to access it from there. I just want to type into the cell itself.
1. Excel version is Microsoft Office pro 2016
2. The function is prefaced with "Public"
3. The vba is located in a new module not in "ThisWorkbook" area.
Code is:
What on earth am I doing wrong?![]()
Public Function CountColorIf(rSample As Range, rArea As Range) As Long Dim rAreaCell As Range Dim lMatchColor As Long Dim lCounter As Long lMatchColor = rSample.Interior.Color For Each rAreaCell In rArea If rAreaCell.Interior.Color = lMatchColor Then lCounter = lCounter + 1 End If Next rAreaCell CountColorIf = lCounter End Function
Thanks
Bookmarks