2

I have an Excel VBA function that takes a number of optional parameters, including an optional Range:

Function DazBeta(A As Range, Z As Range, _
        B As Integer, _
        Optional Freq As Integer = 1, _
        Optional c As Double = 0, _
        Optional r As Range, _
        Optional Pct As Boolean = True, _
        Optional Label As Integer = 1)

I am translating to VB.NET, and it's the optional Range that is giving me grief because VB.NET does allow optional Ranges. Or rather, optional parameters must provide a default value.

What is the recommended way to change the VB.NET function signature so that the code is callable from an Excel cell as a UDF? (The VB.NET implements a UDF, the assembly is registered as a COM server, and the Excel spreadsheet is told of this server and type library, allowing the VB.NET code to be called from an Excel spreadsheet cell.)

I have other compilation problems, so I have not been able to explore this. I am thinking that accepting an optional Object (default value Nothing) might work and then I could cast the Object to a Range. Alternatively, if there were a default value that could be specified with an optional Range, that would work, too.

Any suggestions?

1 Answer 1

3

The default value for an optional Range parameter would be Nothing

Sign up to request clarification or add additional context in comments.

1 Comment

So, totally not a problem. Wow, the shame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.