+ Reply to Thread
Results 1 to 16 of 16

dependent comboboxes

  1. #1
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    dependent comboboxes

    Hi....I have 2 comboboxes on a user form. the first has a list of all 12 months which are listed on a worksheet named "Lists" the next 2 columns of data on that sheet list the dates of the time periods for that month. what i need is for the 2nd combo box to list the pay period dates from the neighboring 2 cells next to the month the user selects

    example:
    column G..........column H..........Column I
    Month...............1st - 15th..........16th - Last day of month

    so if the user selects whatever month is listed in cell G5 from combobox1, then combobox2's list should be populated with the values from cells H5 and I5

    Similarly I have another user form which has a combobox that pulls its list from the same worksheet with names of locations in column E, and I would like to have a dependent textbox display the address of the location from the neighbor cell in column F

    example:
    column E..........column F
    KMART...............4325 Broadway St, Eureka

    I have seen similar examples of this but am not quite sure how to edit the code to match my needs....can someone show me how??? thanks for all the help...this forum has already helped me more than i could have imagined. No rush, just a little personal project...i am patient, thanks again

  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: dependent comboboxes

    This example uses listboxes,but can be adapted to work with Comboboxes.An example work book would help

    LinkedListBox.zip
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    hi Roy, thanks for the quick response. I'm not sure how to make that work for me. My combo boxes are on User Forms....i'm not great at this....i just don't know how to edit that code because i don't understand it

    Please Login or Register  to view this content.
    This brings up an entire column of info into a list. I need to bring up in the dependent textbox just 1 result, and in the dependent combobox just 2 results, both in neighboring columns....I'm afraid I don't know VBA well enough to edit this to do that...i need the dependent textbox to work just like vlookup would. Anyway thanks for your input andi will keep trying to figure it out, your input is much appreciated
    Last edited by humboldtguy; 05-14-2010 at 03:21 AM.

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: dependent comboboxes

    You don't need (and shouldn't use) another combobox to display the values of two cells. A combobox is used to provide a choice of selections and you simply want to display values dependent on the selection. Use a text box to do this.

    See attached exampe. It uses a combobox to select the month and a text box to display the corresponding pay period.

    Code for the combobox change event.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  5. #5
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    Quote Originally Posted by Palmetto View Post
    You don't need (and shouldn't use) another combobox to display the values of two cells.
    Hi Palmetto, thanks for the help, but I don't want to display two values, i want a choice between the 2 values for the dependent combobox. the dependent text box i am doing will display just 1 value...anyway i think that will work for one of the needs i described. will post again after i have tried it out. thanks again, you guys rock

  6. #6
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: dependent comboboxes

    i want a choice between the 2 values for the dependent combobox
    Please Login or Register  to view this content.
    Last edited by Palmetto; 05-14-2010 at 10:10 PM. Reason: amended code to clear combobox

  7. #7
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    Hi again, so that works perfectly for the dependent text box...thank you thank you!! here is the code i ended up with if your curious

    Please Login or Register  to view this content.
    you guys are just awesome....I can't figure out how to edit that to fit my other user form however...I need a combo box so the user has a choice between the 2 time periods. Thanks again, you guys rock!!

  8. #8
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    Quote Originally Posted by Palmetto View Post
    Please Login or Register  to view this content.
    oh wow you replied while i was typing my last reply, will try this out and get back, thanks!!!!

  9. #9
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    hi palmetto, this errors out on me...not sure why, except that I don't understand "option explicit" does this code need to go somewhere besides the combobox change event? here is the code i ended up with, what did i do wrong??

    Please Login or Register  to view this content.
    i put option explicit at the top, but it seemed to end up on the bottom of code i have to format another combobox

  10. #10
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: dependent comboboxes

    Option Explicit is code that forces you to always properly declare variables. It only needs to appear once at the top of any given module. You should never code without it for the reason stated. Turn it on for all Modules via Tools > Options > Require Variable Declaration.

    The code I gave you works fine, so you need to be specific about the type of error you are getting. Which line of code is highlighted when you debug?

    For starters, never reference entire columns as the table array in a look up. Specify the exact range for the look up: e.g. G1:I50

  11. #11
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    here is what is highlighted with the error

    Please Login or Register  to view this content.
    the error code i get is

    "Run-Time Error '1004':

    unable to get the Vlookup property of the WorksheetFunction class"

  12. #12
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: dependent comboboxes

    There is nothing wrong with the way the code is written, far as I can see, though some would use False in place of zero ( 0 ) in the last argument.

    Does Sheet6 exist? The error seems to indicate an invalid range reference.


    EDIT: posted amended code in previous post to clear the combobox2 list when a new selection is made in combobox1
    Last edited by Palmetto; 05-14-2010 at 10:12 PM. Reason: added comment about revised code

  13. #13
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    hi....so here is the code again, edited again.....i changed the name of the combo boxes...just in case you notice that difference....still get the same error...there is a sheet6...it is named Lists.

    Please Login or Register  to view this content.
    I also tried naming the range and changing the code to this

    Please Login or Register  to view this content.
    Still getting same error.....any idea's??? Thanks again for all the help

  14. #14
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: dependent comboboxes

    The only other cause of the error I can think of is the value does not exist in the look up table. Check and make sure that the values populating combobox1 list and the values in the look up table are EXACTLY the same. If there is a trailing space, for instance, it will generate an error. If you were using VLOOKUP in the worksheet you would get the #N/A result if that were the case.

    Failing the above, post a copy of the workbook for review.

  15. #15
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    the combobox is populated with the rowsource property which is set to (Lists!G2:G13). "Lists" is the name of sheet6....so they have no choice but to match each other....is there any way i could messenger or email it to you?? the workbook size is too large to upload here....if not i will find a place to upload and post a link

  16. #16
    Forum Contributor
    Join Date
    10-01-2008
    Location
    Eureka, CA
    Posts
    161

    Re: dependent comboboxes

    i went ahead and uploaded....here is the link...http://www.4shared.com/file/wUcyLbcv..._4_Change.html to see the error click on the command button labeled view, edit or print timesheets....select a month
    Last edited by humboldtguy; 05-14-2010 at 10:44 PM.

+ 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