+ Reply to Thread
Results 1 to 6 of 6

Passing the name of an array

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    Question Passing the name of an array

    I want to call a function several times, but pass in the array it's going to use each time.
    I'm not sure how to do this. I thought i would just pass in the name of the array as a string, but i can't figure out how to use in something like:
     
    Dim NDC11(5000) As String
    
    this = "NDC11"
    
    Function test(this As String)
    
    this(counter) = ActiveCell.Value
    
    End Function
    I just need an example of how it would work. If anyone would have a better way to do it i would be grateful.

    Thanks guys,

    Chris

  2. #2
    Forum Contributor
    Join Date
    12-12-2005
    Posts
    667
    The idea is to make your array Public:
    Public Ar() As String

    Sub testarray()
    ReDim Ar(2)
    Ar(1) = "test"
    Ar(2) = "Test2:"
    retest
    End Sub

    Sub retest()
    MsgBox Ar(2)
    End Sub

    The declaration can be in the main Module, then all other modules will recognize it.
    Best regards,

    Ray

  3. #3
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    One Down, One To Go

    Ok excellent, it took me a bit to realize i you meant i had to make the declaration outside of the macro.

    So, then my second question would be how can i pass the name of the array into the function.
    I want to call the same function multiple times, passing it different arrays to store the data.

    Thanks Ray,

    Chris

  4. #4
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109
    Is it possible to use pointers in an excel macro?
    If i could use pointers i could figure out the solution, but i don't know how to declare them.

    Thanks,

    Chris

  5. #5
    Forum Contributor starryknight64's Avatar
    Join Date
    09-27-2006
    Location
    Missouri
    MS-Off Ver
    2003 (Work) & 2007 (Home)
    Posts
    193
    What ray has done is he has made the array a public or "global" variable. So you do no longer need to pass this array to another function unless it is outside of its scope.
    starryknight64

  6. #6
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109
    Agreed. I decided to use a multi-dimensional array once i realized i could have a variant type

    Thanks Guys,

    Chris

+ 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