Consulting

Results 1 to 2 of 2

Thread: Portion of arrays as argument

  1. #1

    Portion of arrays as argument

    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.

  2. #2
    '========>>
    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
    '<<========

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •