userform combobox populated from two columns of a table

  • Hello all,


    Here is my situation:


    I have a userform called ufExisting. On the userform i have a combobox called cmbExisting.


    Now here is what i'm trying to do.


    On a sheet called "Client Records" i turned it into a table called [ClientRec].


    Now i want to populate the combobox with columns tables 1 and 6.


    The reason i'm doing this is cause the combobox selection will open a sheet in the workbook that is based on the information from the column 1 table.


    Thank you for any assistance that you can provide.

  • Re: userform combobox populated from two columns of a table


    Hey,


    Try this out (just replace Col1 and Col2 with the actual column names in the first two lines):



    Cheers,
    Adrian B.

  • Re: userform combobox populated from two columns of a table


    Hello Adrian


    I tried your code but I get an error message at set rng1. I don't know why it doesn't recognize it.

  • Re: userform combobox populated from two columns of a table


    I would load all the data into the combobox.


    Set the number of columns to however many you want then hide the other columns using the columnwidth property.


  • Re: userform combobox populated from two columns of a table


    I'm doing two columns in the combobox which would look like one.

  • Re: userform combobox populated from two columns of a table


    So you want to concatenate the data from columns 1 and 6 from the table and have the result appear in the combobox list?


    What data is in those 2 columns and how will you use the first column to determine which worksheet to 'open'?


    Could you upload a sample workbook?

    Boo!:yikes:

  • Re: userform combobox populated from two columns of a table


    Column 1 has a project code like "077-09", Column 6 has the project name. Now each sheet in the workbook is title by the job number so in this case "077-09". So it takes the number sequence of ###-## and then opens that worksheet.


    Now I tried Adrian code and it works but instead of shows it like "077-09 Project Name" it goes


    077-09
    Project Name


    so now I just need to have first the columns to combine in the list so it appears at 077-09 Project Name and then once selected the userform has a button that would essentially open the worksheet (Show, Unhide, Select, how ever that is called) and the user would see the project sheet.

  • Re: userform combobox populated from two columns of a table


    So is the sheet simply named after the column one contents?


    If so use my code and


    Code
    Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    Sheets(Me.ComboBox1.Value).Activate
    End Sub


    If the sheet name is a combination of columns 1 and 6 then use


    Code
    Private Sub ComboBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With Me.ComboBox1
    Sheets(.Value & .List(.ListIndex, 5)).Activate
    End With
    End Sub
  • Re: userform combobox populated from two columns of a table


    Hello again,


    I clearly misunderstood you request.


    Please paste the above code in your userform code area:



    Here is the sample workbook:
    forum.ozgrid.com/index.php?attachment/72281/


    Cheers,
    Adrian B.

  • Re: userform combobox populated from two columns of a table


    Thanks royUK for the information. I will test your code once I get the first one from Adrian B's code.


    Now the code for the combo box works except instead of show two columns, all I get is one column with first information and then second information below it. I'm attaching a sample of the workbook to make things easier. Please see what you guys can do to fix it.

  • Re: userform combobox populated from two columns of a table


    Hey all thanks for the help.


    I was able to make a few adjustments and got the code userform to work how I wanted it too. This saved me a lot for the ultimate project I'm working on. I'm including the final code below:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!