+ Reply to Thread
Results 1 to 7 of 7

userform combo box conditional rnages

Hybrid View

  1. #1
    Registered User
    Join Date
    07-27-2012
    Location
    Sydney Aust
    MS-Off Ver
    Excel 2010
    Posts
    92

    Post userform combo box conditional rnages

    I've got a userform with mutliple combo boxes

    Each of the combo boxes selects from a separate named range

    Is it possible to have the options in combo box 2 change depending on the option selected in combo box 1?

    eg

    combo box 1 choices, 1,2,3,4,5 (named range 1)
    combo box 2..........
    if combo box is "1" then select from (named range 2) a,b,c,d,
    if combo box is "2" then select from (named range 3) X,y,z

    then if combo box 2 is X then select from (named range 4) P, Q,R)

    I've used combo boxes in my form but there may be an easier way. I am willing to learn.

    Thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: userform combo box conditional rnages

    Hi,

    Have you tried using a Select Case statement?

    For example:
    Select Case CStr(ComboBox1.Value)
        Case "1"
            With ComboBox2        
                .Clear
                .AddItem "a"
                .AddItem "b"
                .AddItem "c"
                .AddItem "d"
            End With
        Case "2"
            With CombBox2
                .Clear
                .AddItem "x"
                .AddItem "y"
                .AddItem "z"
        Case "3"
            ....and so on
    End Select
    Insert something like this in the ComboBox1_Change() event.

    Hope this helps

  3. #3
    Registered User
    Join Date
    07-27-2012
    Location
    Sydney Aust
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: userform combo box conditional rnages

    ajryan88 thanks for your time to help on this problem.

    When I click on the second combobox i have no options.


    this is the code I have

    Private Sub CBox_Hazard_Group_Description_Change() ' combobox 1
    Select Case CStr(CBox_Group_name.Value) 'combobox 2
        Case "HEALTH"
            With CBox_Hazard_Group_Description 'combobox 1
                '.Clear
                .AddItem "Hazards with potential to impact personal health and well-being"
                .AddItem "b"
                '.AddItem "c"
                '.AddItem "d"
            End With
        Case "Safety"
            With CBox_Hazard_Group_Description
                .Clear
                .AddItem "Hazards with potential to impact personal safety or Plant stability"""
                '.AddItem "y"
                '.AddItem "z"
        'Case "3"
            
    End Select
    End Sub

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,849

    Re: userform combo box conditional rnages

    You are using the Change event from CBox_Hazard_Group_Description but then using it to update the same combo box. You should be using the Change event from CBox_Group_name.
    Private Sub CBox_Group_name_Change() ' combobox 1
    Select Case CStr(CBox_Group_name.Value) 'combobox 2
        Case "HEALTH"
            With CBox_Hazard_Group_Description 'combobox 1
                '.Clear
                .AddItem "Hazards with potential to impact personal health and well-being"
                .AddItem "b"
                '.AddItem "c"
                '.AddItem "d"
            End With
        Case "Safety"
            With CBox_Hazard_Group_Description
                .Clear
                .AddItem "Hazards with potential to impact personal safety or Plant stability"""
                '.AddItem "y"
                '.AddItem "z"
        'Case "3"
            
    End Select
    End Sub
    Last edited by 6StringJazzer; 09-05-2013 at 09:50 AM. Reason: totally rewritten
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Registered User
    Join Date
    07-27-2012
    Location
    Sydney Aust
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: userform combo box conditional rnages

    oh okay thats my issue

    ill have a looksee in the morning

    cheers

  6. #6
    Registered User
    Join Date
    07-27-2012
    Location
    Sydney Aust
    MS-Off Ver
    Excel 2010
    Posts
    92

    Re: userform combo box conditional rnages

    I still have the same issue.

    Does the RowSource for the combobox have to be empty?

    CBox_Group_name_Change()
    
    Select Case CStr(CBox_Group_name.Value)
        Case "Health"
            With CBox_Hazard_Group_Description        
                .Clear
                .AddItem "Hazards with potential to impact personal health and well-being"
                End With
        Case "Safety"
            With CBox_Hazard_Group_Description        
                .Clear
                .AddItem "Hazards with potential to impact personal safety or Plant stability"
                End With
    Case "Environment"
            With CBox_Hazard_Group_Description        
                .Clear
                .AddItem "Hazards with potential to impact the environment"
                End With
    Case "Process Safety"
            With CBox_Hazard_Group_Description        
                .Clear
                .AddItem "Hazards associated with work on Facility Safety & Emergency Systems"
                End With
    Case "ISSoW"
            With CBox_Hazard_Group_Description        
                .Clear
                .AddItem "Permits & Certificates"
                End With
    End Select
    it may be easier to create new user forms for the different options.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: userform combo box conditional rnages

    If RowSource wasn't empty you would receive an error message.

    Not sure having multiple userforms will make things easier.

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Combo Box Userform To Open 2nd Combo Box
    By WPJensen in forum Excel General
    Replies: 8
    Last Post: 03-10-2011, 06:33 AM
  2. Userform Combo box
    By zerodegreec in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2010, 02:41 PM
  3. Combo box within Userform
    By wilwhiting in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2008, 05:14 AM
  4. Combo Box up in the userform
    By koda86 in forum Excel General
    Replies: 2
    Last Post: 06-19-2007, 06:27 AM
  5. [SOLVED] Userform combo box
    By Andy the yeti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2006, 03:10 PM

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