This post 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.
My current work-around is to use the "f"unction pop-up to build a list with empty commas, for example =YesNo(B4,,,,,"value"), but I'd much rather pass named parameters if possible. I also discovered Application.MacroOptions, which makes the work-around work better.
Here's my header. The function works (body not included) but would be even easier to use if I can supply named parameters from the Excel spreadsheet formula:
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!
Bookmarks