Custom Function

mouse88

Board Regular
Joined
May 24, 2011
Messages
148
I want to write a custom function which takes a range as a parameter such as the sum function:

Code:
SUM(A1, C56)

Do I just use a range as a parameter?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
try this


Excel Workbook
ABCD
114
21
31
Sheet1


in the name manager put the name as suma1toc56
and put the following formula

=SUM(OFFSET(Sheet1!$A$1,,,56,3))
 
Upvote 0
Sorry don't think you understood.

I am writing a custom function and want to pass several ranges as parameters but dont know how.

This is what I have tried so far:

Code:
Public Function SUMIFNOTERROR(Cells() As Range) As Variant
Dim ReturnValue As Date
Dim Cell As Range
ReturnValue = TimeValue("00:00:00")
For Each Cell In Cells
    If Cell.Value <> "#N/A" Or Cell.Value <> "#DIV/0" Or Cell.Value <> "#REF!" Then
        ReturnValue = ReturnValue + Cell.Value
    End If
Next Cell
SUMIFNOTERROR = TimeValue(ReturnValue)
End Function

I want to be able to pass in several cells so I would use the formula like this:

Code:
=SUMIFNOTERROR(B2:B5)

With the current code I get a #VALUE! error. Im not sure if this is to do with any of the data types or because of the parameters in my function.
 
Upvote 0
Ok im getting somewhere with this now.

My question now is:

If I have a parameter in my function (Values As Variant), how can I pass an array of values to the function in a formula?
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,267
Members
452,902
Latest member
Knuddeluff

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