+ Reply to Thread
Results 1 to 7 of 7

UserForms & dependent ComboBoxes?

  1. #1
    Registered User
    Join Date
    05-10-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    4

    UserForms & dependent ComboBoxes?

    Hi all,

    Can anyone help out with making a UserForm that has multiple ComboBoxes which have limited choices for the user based on what the previous drop down choice was?

    For example, let's say that column A contains states, column B contains cities and column C contains boroughs/neighborhoods/towns.

    I'd like to make it so that once the user selects California from the first drop down box, then only cities in California would appear in the second drop down box. Then once they chose their city, only boroughs/neighborhoods/towns from that city would be selectable in the third drop down box.

    I appreciate the help!

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

    Re: UserForms & dependent ComboBoxes?

    Basic example attached. This should give you a good idea of how to proceed.

    Sheet1 holds lists for which named ranges were created.
    Userform contains two combo boxes.

    Code in the form initialize event
    Please Login or Register  to view this content.
    Code for combo box #1

    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.

  3. #3
    Registered User
    Join Date
    05-10-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: UserForms & dependent ComboBoxes?

    Thank you Palmetto. Here's my new (but I think easy to solve) issue.

    How can I use lookups in VB to get data populated into certain cells based on what is selected from a drop down menu?

    I am able to get data to print on the worksheet with these:
    .Cells(lRow, 2).Value = Me.ComboBox1.Value
    .Cells(lRow, 4).Value = Me.ComboBox2.Value


    But the following gives me an "Expected: list separator or )" error:

    .Cells(lRow, 1).Value = Application.VLOOKUP(Me.ComboBox1.Value,J1:K18,2,FALSE)

    The range J1:K18 contains cities in column J and corresponding zip codes in column K.

    I'd like to print the corresponding zip code based on the city from Me.ComboBox1.Value.

    Am I far off?


  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: UserForms & dependent ComboBoxes?

    The range reference is incorrectly qualified: it specifies only cell adresses without telling VBA that it is a range object.

    Please Login or Register  to view this content.

    Use (adjusting the sheet name as needed):
    Please Login or Register  to view this content.
    Last edited by Palmetto; 05-11-2010 at 09:27 PM. Reason: correct typo in code

  5. #5
    Registered User
    Join Date
    05-10-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: UserForms & dependent ComboBoxes?

    Hmm, I used this:

    (The worksheet with the cities and zip code table is called Sheet1 by the way.)

    .Cells(lRow, 1).Value = Application.VLookup(Me.ComboBox1.Value, Sheet1!Range("J1:K18"), 2, False)



    And I'm getting the following error:


    Run-time error '438':
    Object doesn't support this property or method

  6. #6
    Registered User
    Join Date
    05-10-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: UserForms & dependent ComboBoxes?

    Just bumping for a response.

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

    Re: UserForms & dependent ComboBoxes?

    Oops! Typo in the code - inadvertently used an exclamation symbol (force of habit from typing sheet references in formula).

    See previous post for corrected code using the decimal point.

+ 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