+ Reply to Thread
Results 1 to 4 of 4

Create a variable with a dynamic name

  1. #1
    Registered User
    Join Date
    03-07-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007/2010, Outlook 2007/2010
    Posts
    60

    Create a variable with a dynamic name

    I have an IF statement contained within a WHILE loop which runs down a column. At every passing I want a new String variable created with the row number as part of the name. Thus on the first pass a string variable would be created called String1, on the second there would be a String2 variable created, and so on.
    What I'm really trying to do here is create a message box with a message generated each time the loop is performed. This is me trying to work around the length limit imposed on the String variable. Another solution to this is also welcome, this is just the solution I had in my head.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Create a variable with a dynamic name

    Dralky,

    Its difficult to give helpful advice without context, but I think you're looking for how to use arrays. Here is an example:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Create a variable with a dynamic name

    Hi

    I suggest that you look at using a collection.

    Please Login or Register  to view this content.
    gives you access to MyVariable(1) to MyVariable(Massive)

    http://www.functionx.com/vbaexcel/objects/Lesson6.htm

  4. #4
    Registered User
    Join Date
    03-07-2013
    Location
    Phoenix, AZ
    MS-Off Ver
    Excel 2007/2010, Outlook 2007/2010
    Posts
    60

    Re: Create a variable with a dynamic name

    Thanks, the Array suggestion worked. Now I'm just to get the message box to display every instance of the array :P

+ 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