+ Reply to Thread
Results 1 to 5 of 5

Select Cases and Comboboxes

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Select Cases and Comboboxes

    Hello everyone. I have an outstanding problem that I could use some help on.

    I have a userform that contains two comboxes. If the user selects value "A" in the first combobox, I want a specified range in a spreadsheet to be used as the rowsource for the second combobox.

    If the user selects value "B" in the first combobox, I want a different specified range in a spreadsheet to be used as the rowsource for the second combobox.

    Below is the source code.

    Option Explicit
    
    Private Sub ComboBox1_Change()
    Application.ScreenUpdating = False
    Select Case ComboBox1.Value
        Case Range("A1")
            ComboBox2.RowSource = "TrackerManagement!C2:C10"
        Case Range("A2")
            ComboBox2.RowSource = "TrackerManagement!D1:D10"
    End Select
    
    End Sub
    Now this code is in the actual userform itself. A seperate module "Module 3" shows the form :

    Option Explicit
    Sub CommandButton31_Click()
        Application.ScreenUpdating = False
        TrackerManagement.Show
    End Sub
    it's not working, and I cannot figure it out. Any help is greatly appreciated.
    Last edited by AnthonyWB; 01-12-2011 at 08:28 PM.

  2. #2
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Select Cases and Comboboxes

    Ok, it sort of works now with the following code:

    Option Explicit
    
    Private Sub ComboBox1_Change()
    
    Application.ScreenUpdating = False
    
    Sheets("TrackerManagement").Select
    Select Case ComboBox1.Value
        Case Range("A1")
            ComboBox2.RowSource = "TrackerManagement!C2:C10"
        Case Range("A2")
            ComboBox2.RowSource = "TrackerManagement!D1:D10"
    End Select
    
    End Sub
    The problem now is quite wierd. When the user selects a value in the first combobox, correct values are loaded into the second combobox however when you press the down arrow to display the values it comes up behind the other combobox.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,234

    Re: Select Cases and Comboboxes

    Hi Anthony,

    I think you need to use
    Case A
    Case B
    instead of
    Case Range("A1")
    Case Range("B1")
    If that doesn't work try
    Case Range("A1").Value
    Case Range("B1").Value
    See examples on http://www.ozgrid.com/VBA/select-case.htm
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,234

    Re: Select Cases and Comboboxes

    After searching the net for a long time it was easier to build a short example

    See attached.
    Attached Files Attached Files

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,234

    Re: Select Cases and Comboboxes

    Here is the Case way to do this problem
    Private Sub ComboBox3_Change()
        Select Case ComboBox3.Text
            Case Is = "A"
                ComboBox2.RowSource = "Sheet1!C2:C7"
            Case Is = "B"
                ComboBox2.RowSource = "Sheet1!e2:e7"
        End Select
    End Sub
    Who would have guessed we needed "Case Is = " to make the syntax right.
    Attached Files Attached Files

+ 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