+ Reply to Thread
Results 1 to 4 of 4

Getting a combo/list box to populate based on the other

Hybrid View

  1. #1
    Registered User
    Join Date
    06-14-2011
    Location
    galway
    MS-Off Ver
    Excel 2003
    Posts
    11

    Getting a combo/list box to populate based on the other

    New User here,

    Hopefully someone can help me try and sort a problem that my head just can't get around. I have the USer form set up and working etc. However I would like to know how to populate a combo / list box to populate based on the selection in another.

    I have a worksheet with 2 colums i.e Column 1 = Report Name, Column 2= How the report is output. So in essence A2 is directly related to B2 and are dependent on nothing else.

    I just can't get this working in VBE.

    Any help would be greatly appreciated.

    Niall
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Getting a combo/list box to populate based on the other

    Try this amended code
    Private Sub cboReport_Change()
    Me.cboOutput.ListIndex = Me.cboReport.ListIndex
    End Sub
    
    Private Sub cmdClose_Click()
      Unload Me
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim cReport As Range
    Dim cOut As Range
    Dim ws As Worksheet
    Set ws = Worksheets("ReportLookup")
    
       Me.cboReport.List = ws.Range("Report_Name").Value
       Me.cboOutput.List = ws.Range("Output").Value
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-14-2011
    Location
    galway
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Getting a combo/list box to populate based on the other

    Quote Originally Posted by royUK View Post
    Try this amended code
    Private Sub cboReport_Change()
    Me.cboOutput.ListIndex = Me.cboReport.ListIndex
    End Sub
    
    Private Sub cmdClose_Click()
      Unload Me
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim cReport As Range
    Dim cOut As Range
    Dim ws As Worksheet
    Set ws = Worksheets("ReportLookup")
    
       Me.cboReport.List = ws.Range("Report_Name").Value
       Me.cboOutput.List = ws.Range("Output").Value
    End Sub
    RoyUK,

    You have sorted in under 1 minute what has taken me days not to find out. Superb and thank you so much for this. Very much appreciated. No doubt I will be back to annoy (consult) you soon.

    Super.

    Thanks again,

    Niall

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Getting a combo/list box to populate based on the other

    Note the different way of loading the ComboBoxes - it's much neater & more efficient

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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