Results 1 to 3 of 3

Thread: Enable And Disable Controls Based On Selection In Previous Combo Box

  1. #1
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12

    Enable And Disable Controls Based On Selection In Previous Combo Box

    Hi

    With the userform in the "Category" Combobox if "Internal" is selected then the "External" Combobox entries are not visible/cannot be selected...if Category "External" selected then "Internal" Combobox entries are not visible/cannot be selected....
    Also with the above can the selections in all box`s in userform only be made in order.So a date must be entered first,machine second,Category third....etc..etc..if a box is selected before a entry is entered in any box above it then that box entries remain invisible until entries are entered in order starting at the very top....a message boxs opens saying entry must be made in Date,Machine,Category etc..etc..

    Thanks

    Paul
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10
    Here's what I've added to your code

    Code:
    Private Sub ComboBox1_Change()
    
        ComboBox2.Enabled = ComboBox1.Text <> ""
        
    End Sub
    
    Private Sub ComboBox2_Change()
    
        ComboBox3.Enabled = ComboBox2.Text <> ""
    
    End Sub
    
    Private Sub ComboBox3_Change()
    
        Dim lngCol As Long
        With Worksheets("sample")
            lngCol = .Rows(2).Find(What:=Me.ComboBox3.Text, lookAt:=xlWhole).Column
            Me.ComboBox4.List = .Range("A4:A" & .Cells(.Rows.Count, lngCol).End(xlUp).Row).Offset(, lngCol - 1).Value2
            Me.ComboBox5.List = .Range("A4:A" & .Cells(.Rows.Count, lngCol + 1).End(xlUp).Row).Offset(, lngCol).Value2
            Me.ComboBox6.List = .Range("A4:A" & .Cells(.Rows.Count, lngCol + 2).End(xlUp).Row).Offset(, lngCol + 1).Value2
            Me.ComboBox7.List = .Range("A4:A" & .Cells(.Rows.Count, lngCol).End(xlUp).Row).Offset(, lngCol - 1).Value2
            Me.ComboBox8.List = .Range("A4:A" & .Cells(.Rows.Count, lngCol + 1).End(xlUp).Row).Offset(, lngCol).Value2
        End With
        Frame1.Enabled = UCase(ComboBox3.Text) = "INTERNAL"
        Frame2.Enabled = Not Frame1.Enabled
        ComboBox4.Text = ""
        ComboBox5.Text = ""
        ComboBox6.Text = ""
        ComboBox7.Text = ""
        ComboBox8.Text = ""
        
    End Sub
    In addition, I've also changed the style of your drop-down box to List-box instead of Combo-box. That way, user cannot 'type' anything that is not there in the list. In addition, I've also changed the Enabled property to false, and based on selection of value in the hierarchical order, the combo-boxes will get enabled.
    Attached Files Attached Files
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    Thank you Excel Fox

Similar Threads

  1. Replies: 8
    Last Post: 08-17-2013, 02:42 PM
  2. Replies: 8
    Last Post: 08-17-2013, 04:03 AM
  3. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  4. Replies: 2
    Last Post: 04-10-2013, 12:40 AM
  5. Replies: 3
    Last Post: 04-08-2012, 08:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •