UDF not working

NMitch

New Member
Joined
Feb 19, 2014
Messages
19
Hi all,

This is for Excel 2013, and here is my code, which has worked before:

Code:
Public Function SumByColor(CellColor As Range, rRange As Range)    
    '   CellColor is the cell containing they colour type you are searching for
    '   rRange is the range of cells to add, if the colour matches
    Dim cSum As Long
    Dim ColIndex As Integer
    ColIndex = CellColor.Interior.ColorIndex
    For Each cl In rRange
        If cl.Interior.ColorIndex = ColIndex Then
            cSum = WorksheetFunction.Sum(c1, cSum)
        End If
     Next cl
     SumByColor = cSum
End Function

When using this in a macro-enabled workbook, the #NAME ? result appears.

The function used to be just a normal function, which resides in my PERSONAL.XLSB, but changed to PUBLIC to see if that made a difference.

I have a habit of doing things, like formulae, in lower case, then seeing if it changes to the proper case after pressing Enter. The UDF is SumByColor(), but the formula shows sumbycolor().

Can someone let me know what I'm doing wrong?

Thank you,
 
Last edited:

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe something like this...
=PERSONAL.XLSB!SumByColor(A2, B2:B10)
adjust the function parameters to fit with your case.

M.
 
Upvote 0
Ok, while the formula looks like it works, the UDF returns the value 0.

The formula is =PERSONAL.XLSB!sumbycolor(E623,F623:F626)

Can someone please let me know what I'm doing wrong? (The UDF is in the first post above.)

Thank you,
 
Last edited:
Upvote 0
Have you named anything else 'sumbycolor'?
 
Upvote 0
Thanks Norie, good suggestion.

I searched the entire workbook, then all open modules, but could only find the instances referred to in this thread. (I used "sumbycolor" as the search text. I even searched for occurrences of the Australian spelling for colour.)

Thank you,
 
Last edited:
Upvote 0
Did you check module named, named ranges etc.?
 
Upvote 0
Thanks again, Norie, but there are no modules in open workbooks nor ranges using the same name.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,656
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top