PDA

View Full Version : Portion of arrays as argument



MamboKing
07-12-2008, 10:22 AM
This question may be trivial and silly, but... not for me. Apologies if it is.

I cound neither find code examples nor formal explanations regarding this:

Is it possible to pass to a Sub or Function just part of an array w/o creating another variable?

Suppose you have an array like myarray(1 To N, 1 To M)

Is it possible to do semething like:

Call A_Sub(myarray(1 To N, M))

which gives to A_Sub the M column, i.e. the elements 1 to N of the column M.
That's without copying that portion of myarray into another array and give this last to A_Sub.

If something similar is possible, would you pls give me an example or a link with the syntax?

Thanks and Regards.

norman_jones
07-12-2008, 05:34 PM
'========>>
Option Explicit

Public Sub Tester()
Dim arrIn As Variant
Dim arrOut As Variant
Dim iCol As Long

arrIn = ActiveSheet.Range("A1:G20").Value
iCol = UBound(arrIn, 2)

arrOut = Application.Index(arrIn, , iCol)

Call Demo(arrOut)

End Sub

'-------------->>
Public Sub Demo(arr As Variant)
Dim iCtr As Long

For iCtr = 1 To UBound(arr, 1)
Debug.Print arr(iCtr, 1)
Next iCtr

End Sub
'<<========