+ Reply to Thread
Results 1 to 21 of 21

Select Subset of Table in List Box

  1. #1
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Select Subset of Table in List Box

    I have 2 List Boxes, State and City. I am trying to select a city in a list box that is based upon a set value filtered by state. i.e. if I have list of 50 states and list of 1000 cities, I want to be able to select a state then select a city within that state (only see the cities within a selected state).

    Any help is greatly appreciated.
    Attached Files Attached Files
    Last edited by stubbsj; 10-17-2011 at 08:56 AM. Reason: Change email subscription

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Select Subset of Table in List Box

    Is a macro solution acceptable?

    My first instinct is to do this with a macro. I would replace your List Validation/dropdown boxes (list boxes is not exactly the right term for these) with comboboxes and write code to respond to changes in them.

    Someone who is really a wiz at formulas might be able to come up with a way to do this without macros but I'm wracking my brain on that.
    Last edited by 6StringJazzer; 10-14-2011 at 10:27 PM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Select Subset of Table in List Box

    macro solution attached
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Thanks 6StringJazzer

    I looked at the code to shorten the city list and that is spot on. That allows me the select the correct city. How can I reference a cell to the info in the "Select City" combo box? I need to be able to filter a report by city as well as include the city in pivot tables.

    Jim
    Last edited by stubbsj; 10-15-2011 at 09:35 AM.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Select Subset of Table in List Box

    I should have mentioned that. I linked the contents of each combo box to the cell where it's located. So if you need to use the selected city name in a formula, you can reference the cell that is under the Select City combo box (in this case B13). This is the same cell where you had your data validation dropdown box, so everything you've already done is completely compatible with the solution I provided.

    With comboboxes, you can go to the ribbon and select Developer, then click on Design, then you can right-click on the combobox and select Properties form the pop-up menu to see a list of Properties. The LinkedCell property tells you what cell contains the same value that the user selected in the combobox.

  6. #6
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Got it. Thanks again. Let's see if some formula guru can solve this. Otherwise, I'mgoing to go with your suggestion!

  7. #7
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    6StringJazzer - One more question. How do I use your solution on multiple row? I've attached an update to your previous file.
    Attached Files Attached Files

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    Try this formula method using dynamic named ranges.
    Note Data in G13:Hxx must be sorted by Column G (State)
    The list must be continuous.
    "xx" can be any number.

    Name:= States
    Refers To:=
    Please Login or Register  to view this content.
    Name:= CitiesByState
    RefersTo:=
    Please Login or Register  to view this content.
    Data Validation B13
    Allow:= List
    Source:=
    Please Login or Register  to view this content.
    Data Validation B14
    Allow:= List
    Source:=
    Please Login or Register  to view this content.
    Last edited by Marcol; 10-15-2011 at 11:03 AM. Reason: Can't access Go Advanced to attach sample, see next post.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    For some reason I can't edit the last post to add the attachment I thought I posted.
    Here it is
    Attached Files Attached Files

  10. #10
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Excellent - Thank You Marcol

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    Here is an improved solution for your problem.

    This should be much quicker than my original proposal, it no longer uses the volatile function OFFSET() and includes a dynamic array to create a new list of states by removing duplicates from your data table.

    Just add the State Code to Column G, and the city to Column H, then sort on Column G.
    Any new state code added to "G" will automatically be added to Column E.

    INDEX() is a really powerful non-volatile function, in most applications.
    See this article for more information
    The Imposing INDEX

    Hope this helps
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Thanks Marcol. Great solution and I'm almost there. Sorry but my original requirement was not stated correctly. I need your solution to work on multiple rows within a Tab as well as work on multiple Tabs. I've attached an updated version of your file. Hope you can still help
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Sorry, I didn't see your new post when I sent my reply just a few minutes ago.

    Will the newer solution you just sent work on the multiple rows and tabs?

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    Okay, happy to have helped so far, got to go for a while, I'll look again later.
    Have you seen my last post?
    The timing of your last post and mine was amazingly coincidental!

    [EDIT]
    And again!!!!!
    Haven't had time to consider it yet. Will be back later.
    Last edited by Marcol; 10-16-2011 at 09:30 AM.

  15. #15
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Yes it was. Too funny.

  16. #16
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Select Subset of Table in List Box

    - the title of this thread doesn't match the content of the question: that is about dependent validation, not listboxes.

    In this case I'd prefer a VBA-approach (see the attachment).
    In this attachment I made a separate worksheet containing the 'database'.
    Last edited by snb; 10-16-2011 at 11:07 AM.



  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    This workbook is a small alteration to the one in Post#11, see there for more info.
    Drag the Columns A:B down to extend the validation rows. (Note the difference in the $ "Anchors" in the names)

    Not sure what you need in Column C, Sheets "Food" and "Sites" appear to be the same.
    If you need more like that then just copy the Sheet "Food" then rename it to your needs, Column C header will change to suit.

    Best if you can stay away from VBa if you can, many companies do not allow macros on their systems, and of course they will not work if the book is opened with macros disabled.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Thanks Marcol. This was my first submission to the ExcelForum so I wass not sure how to go about things. I used a sample of Cities by State. The Workbook that I am working with tracks various costs associated with different data centers globally. Each Site has 1 or more Clients. On each spreadsheet, I need to be able to add additional costs (by row) and tie it to a particular Client by Site. I should have set up my original sample that way. May have made more sense. I'm going to mark this as solved but if it's OK with you, I might have additional questions. I really appreciate your help.

  19. #19
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Hi Marcol -

    I cannot get the curly brackets on Lookup!A2 to copy over (only the formula copies)

    And....my group asked if they could add an additional field "Region" so that the sequence would go 1) Select Region, 2) Select State 3) Select City.

    I added a new file for you.

    Thanks for your help.
    Attached Files Attached Files
    Last edited by stubbsj; 10-17-2011 at 04:31 PM.

  20. #20
    Forum Contributor
    Join Date
    10-07-2011
    Location
    Plano, TX USA
    MS-Off Ver
    Excel 2013
    Posts
    141

    Re: Select Subset of Table in List Box

    Hi Marcol. Figued it all out last night (Curly Braces, adding Region, etc). Could not have done it without you help. Thanks for being patient with me and for all your help.

  21. #21
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Select Subset of Table in List Box

    Happy to have been of some help.

    Sorry I missed your earlier post, but you solved it yourself, that's a good way to learn!

+ 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