+ Reply to Thread
Results 1 to 3 of 3

passing a dimension of an array to a function

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2008
    Posts
    21

    passing a dimension of an array to a function

    Hi there,
    I am contacting you with this first thread.
    I have read very carefully following thread.

    http://www.excelforum.com/excel-prog...-function.html

    It helps me to introduce my question, that I think it is at an upper level.
    MY question is as follows.
    Let’s suppose to have an array of two dimensions, ex
    Arr(a,b)
    ,
    Let’s suppose that I have to call a function, called FunctionA, and to pass the array
    According to the post, I would have to call
    FunctionA(arr)
    My question is: let’s suppose that I want to pass to the FunctionA the sole values of array (a,n) – where n is a number between 1 and b.
    How can I pass this to the function.
    I was thinking to something as
    FunctionA(arr,n)
    and
    public functionA(arr() as single,index as single)
    argument = arr(a,index)
    end function

    Please, has anybody a different solution for this ?

    many thanks

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: passing a dimension of an array to a function

    hi MrReds, I hope I understood you right:

    Sub test()
    Dim arr(1 To 2)
    arr(1) = 10
    arr(2) = 20
    MsgBox Func(arr)
    End Sub
    
    Function Func(arr)
    Func = arr(1)
    End Function

  3. #3
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: passing a dimension of an array to a function

    If I understood what you want, you can use
    application.index(arr, a, 0)
    to get all values from 1 to b for item a of the array, and pass that as a new array.
    Good luck.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1