Returning Multiple Arguments from an Excel VBA Function

A

aussie_craig

Thanks Nick.
How do I access the 2 returned values in the Main Routine ?

Can I reference them in the Main Routine by AddressSplit(0)
AddressSplit(1) and if so do I need to Dim AddressSplit in a particla
manner in the Main Routine

ie
Private Sub CommandButton1_Click()
MsgBox AddressSplit ("qwerty")(0)
A = AddressSplit(0)
B = AddressSplit(1)
End Sub
 
N

NickHK

Craig,
For brevity I wrote the code as such to show the basic. Actually, you may
want to:

Private Sub CommandButton1_Click()
Dim Answers() as string

Answers=AddressSplit ("qwerty")
'Do what you want with Answers(0), Answers(1),,,Answers(n)
'Maybe
MsgBox Answers(0) & ", " Answers(1)
End Sub

Returning an array, rather than using ByRef argument allows for expansion of
the number of return elements. Whether this is important will depend on what
you trying to achieve.

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top