Passing optional arguments with named parameters from the spreadsheeet to a custom function (UDF)

Cornan

New Member
Joined
Aug 7, 2017
Messages
1
This is not about passing optional arguments within VBA. This is about passing optional arguments from the spreadsheet to a custom function written in VBA. I've been surprised to find not a single mention of passing optional arguments, especially named parameters, from the spreadsheet.

Here's my header. The function works (body not included) but won't be of much use if I have to put in a lot of commas to get to the optional arguments:

Public Function YesOrNo(InputValue, _
Optional InvalidResponse As String = "xlErrValue", _
Optional AcceptTF As Boolean = True, _
Optional Accept01 As Boolean = True, _
Optional AcceptTrueFalse As Boolean = True, _
Optional YesValue = "Yes", _
Optional NoValue = "No") As String

YesNo = "Of Course" ' dummy function body

Exit Function

Is there a way to pass optional arguments by name, from the spreadsheet to the VBA custom function (aka UDF) ???


Thanks!
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
As far as I know functions on worksheets, whether native or UDF, don't work with named arguments, optional or otherwise.
 
Upvote 0
Welcome to Mr Excel

Maybe this can help
Formulas > Insert Function
in Select a Category pick User Defined and select your function

M.
 
Upvote 0
You could pass the entire parameter list as a string, then write a parser in your routine to handle it.

=YesOrNo("AcceptTF:=TRUE, YesValue:=Y")

Probably not what you're looking for, but I'm not sure there's a better option.
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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