Returning Multiple Arguments from an Excel VBA Function

  • Thread starter Thread starter aussie_craig
  • Start date Start date
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
 
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
 
Back
Top