+ Reply to Thread
Results 1 to 4 of 4

Select Case in a loop something like this possible?

  1. #1
    Registered User
    Join Date
    03-29-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    9

    Select Case in a loop something like this possible?

    What I currently have:

    Private Sub ComboBox1_Change()
    Select Case ComboBox1.Value
    Case Range("H184"): Range("H8") = Range("G184")
    Case Range("H185"): Range("H8") = Range("G185")
    Case Range("H186"): Range("H8") = Range("G186")
    Case Range("H187"): Range("H8") = Range("G187")
    End Select
    End Sub

    What I'd prefer (I know it's wrong but you get the gist of it):

    Private Sub ComboBox1_Change()
    Select Case ComboBox1.Value (For i = 4:7)
    Case Range("H18%i%"): Range("H8") = Range("G18%i%")
    End Select
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: Select Case in a loop something like this possible?

    Range("G184") represents 1 value at this location

    What does this represent?

    Range("H184"): Range("H8")


    It's like saying

    Does 4:6 = 9

    Also

    What does this mean

    i = 4:7
    Last edited by Dennis7849; 03-29-2012 at 03:25 PM.

  3. #3
    Registered User
    Join Date
    03-29-2012
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Select Case in a loop something like this possible?

    The above works fine, but too much typing for when there are many more cases.

    i=4:7 means this:

    For i = 4 To 7
    CStr(Range("H18" + CStr(i)))
    Next i

    I'd like to loop through all of those Cases w/o having to type out each individual Case.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Select Case in a loop something like this possible?

    Perhaps

    Please Login or Register  to view this content.
    @Dennis: The colon separates the Case statement from the assignment statement.
    Last edited by shg; 03-30-2012 at 09:47 AM.
    Entia non sunt multiplicanda sine necessitate

+ 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