+ Reply to Thread
Results 1 to 3 of 3

Dynamic Assign of Variable

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    Al Ain, UAE
    MS-Off Ver
    Excel 2003
    Posts
    16

    Dynamic Assign of Variable

    Hi,

    Following are my code

    If ComboBox1.Value = "North" Then
    Approach_Max = North_Max
    ElseIf ComboBox1.Value = "West" Then
    Approach_Max = West_Max
    ElseIf ComboBox1.Value = "South" Then
    Approach_Max = South_Max
    ElseIf ComboBox1.Value = "East" Then
    Approach_Max = East_Max
    End If

    For i = 1 To Approach_Max
    'Execute code
    Next i

    North_Max, West_Max, South_Max, East_Max already have values.

    What i want do is to avoid this if condition.

    Is there any way like this

    test = ComboBox1.Value & _Max // for eg: if north, it will be North_Max, so North_Max value will be stored in test.

    For i = 1 To test
    'Execute code
    Next i

    Thanks

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Dynamic Assign of Variable

    If you dimension the Max values as an Array

    Dim Max(0 to 3 ) as Single

    Then you could use the combobox's selected item list index to match to the array's index

    test = Max(ComboBox1.ListIndex)
    Last edited by AlphaFrog; 06-02-2013 at 05:16 AM.

  3. #3
    Registered User
    Join Date
    11-21-2012
    Location
    Al Ain, UAE
    MS-Off Ver
    Excel 2003
    Posts
    16

    Smile Re: Dynamic Assign of Variable

    Thanks... It works perfectly...

+ 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.6.0 RC 1