return an array of values from a function procedure

karthikone

New Member
Joined
May 4, 2006
Messages
19
hi,

i want to know how to return an array of values from a function and use that array values in the calling procedure.

say for eg.


Sub XYZ()

---
---
---

Select Case C

Case "ABC"

Call Gap(arg, arg2, arg3, arg4, arg5)

End Select

End Sub



Function Gap(Par1, Par2, Par3, Par4, Par5)

---
--
--


End Function

I want to return 4 values from the called procedure to the calling procedure. In the calling procedure i want to assign the values which is computed from the called procedure to a variable.


How to do it.


Any help.

thanks[/code]
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
karthik.

here is a simple example:

Code:
Sub Example()

    Dim aryExample()
    
    aryExample = ArrayFunction("Element 1", "Element 2")
    
    For i = LBound(aryExample) To UBound(aryExample)
        MsgBox aryExample(i)
    Next i
    
End Sub

Private Function ArrayFunction(arg1, arg2)

    ArrayFunction = Array(arg1, arg2)
    
End Function

cheers. ben.
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,365
Members
448,888
Latest member
Arle8907

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