+ Reply to Thread
Results 1 to 2 of 2

Thread: Populating variable with array using string name

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    Little Rock, Arkansas
    MS-Off Ver
    Excel 2003
    Posts
    1

    Populating variable with array using string name

    Private Sub testmorestuff()
    Dim avarbooks() As Variant
    Dim intuserselection As Integer
    Const arrayname as string = "avarbooks"
    dim whatthe As Variant


    avarbooks = Array("Book1", "Book2", "Book3", "Book4")
    whatthe = arrayname 'How do I populate whatthe with the array knowing only the name?
    intuserselection = 2
    MsgBox whatthe(intuserselection)
    End Sub

    I need to populate whatthe with Array("Book1", "Book2", "Book3", "Book4"), not with "avarbooks." However, the only way to locate Array("Book1", "Book2", "Book3", "Book4") is by using the name "avarbooks" which is contained in a variable. In other words, I have a variable containing the name of an array and I want to operate on said array. How do I set whatthe equal to the array and not the array name?

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    359

    Re: Populating variable with array using string name

    Is this what you mean
    Sub yourArr()
    Dim avarbooks, whatthe
    Dim intuserselection As Integer
    avarbooks = Array("Book1", "Book2", "Book3", "Book4")
    whatthe = avarbooks
    For k = LBound(whatthe) To UBound(whatthe)
    MsgBox whatthe(k)
    Next
    End Sub
    Hope this helps.
    Anthony
    “Confidence never comes from having all the answers; it comes from being open to all the questions.”
    PS: Remember to mark your questions as Solved once you are satisfied and rate the answer(s) questions.”

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0