Results 1 to 9 of 9

Thread: Update Linked ComboBox List Based On Change In Another ComboBox Selection

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

    Update Linked ComboBox List Based On Change In Another ComboBox Selection

    The code is for a userform.I need some help with adding code.In the userform if Internal (combobox3) is selected then I want Combobox`s 5 & 4 & 6 to have a certain list to choose from.The lists would be for Part,Part No. and Fault for Internal.If In the userform External (combobox3) is selected then Combobox`s 5 & 4 & 6 will have a different list to choose from.The lists would be for Part,Part No. and Fault for External..I would prefer this to be hard coded but if it needs to be called from a sheet then that will also do

    The lists are a example in sheet called Sample...

    At present the combobox 5 & 4 & 6 just have zero`s as entries for now until I work out how to code

    Thanks
    Attached Files Attached Files

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    You've mentioned the same part, part.no and fault. But I am assuming those would be unique parts, part.nos and faults.

    So the code can be

    Code:
    Private Sub ComboBox3_Change()
    
        Dim lngCol As Long
        With Worksheets("sample")
            lngCol = .Rows(1).Find(What:=Me.ComboBox3.Text, lookAt:=xlWhole).Column
            Me.ComboBox4.List = .Range("A3:A" & .Cells(.Rows.Count, lngCol).End(xlUp).Row).Offset(, lngCol - 1).Value2
            Me.ComboBox5.List = .Range("A3:A" & .Cells(.Rows.Count, lngCol).End(xlUp).Row).Offset(, lngCol).Value2
            Me.ComboBox6.List = .Range("A3:A" & .Cells(.Rows.Count, lngCol).End(xlUp).Row).Offset(, lngCol + 1).Value2
        End With
        
    End Sub
    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
    Thanks Excel Fox
    Works very good.
    Would you see any issues with the way the 2 codes are placed in the userform?
    Some code is hard coded and some code is referring to a sheet.
    Thanks
    Paul
    Attached Files Attached Files

  4. #4
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Issues? Can't say until you specify any reason why you think the hard coding might be an issue. Are you going to frequently change the sheet names? Are you going to move the header rows up or down to another row? If yes, then yes the hard coding might be an issue.
    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

  5. #5
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    The only change I made was to add an extra row to the top of the sample sheet and alter the code slightly...it works and I think everything else will remain the same
    Thanks
    Paul
    Attached Files Attached Files

  6. #6
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    So why are you attaching the worksheet again? If you've got it working, do you have any further questions?
    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

  7. #7
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    Just making sure I have done the changes correctly...otherwise no more questions

  8. #8
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    OK, I'm sure you have replicated the solution provided, and I assume you don't have more questions.
    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

  9. #9
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    I actually do have a question please
    Can the userform only show what is in all the combobox`s lists once entries have been entered in order.So for any lists to be visible the date must be entered first followed by Machine followed by Category etc..etc..so if someone tries to enter in the Category before entering a date first a message pops up saying enter a date ...lists are only visible if entries are made in order from the top to the bottom.When a date is entered first then the Machine list becomes visible etc;;etc;; and so on down the userform
    Thanks
    Paul

Similar Threads

  1. Replies: 5
    Last Post: 08-10-2013, 04:15 PM
  2. Replies: 2
    Last Post: 07-28-2013, 09:29 AM
  3. Replies: 1
    Last Post: 05-03-2013, 04:41 PM
  4. Replies: 8
    Last Post: 04-16-2013, 02:04 PM
  5. Combobox VBA update value worksheet
    By Tony in forum Excel Help
    Replies: 4
    Last Post: 10-28-2012, 12:28 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
  •