+ Reply to Thread
Results 1 to 14 of 14

Make autofilter react based upon selection in drop box...

  1. #1
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121

    Make autofilter react based upon selection in drop box...

    I have a pricing model I'm working on where the request is to have all of the line/part items in the model, but only display a subset of those items based upon a sub-line chosen by the user by a drop box that includes all sub-lines.

    Right now the list of parts is a table that I'm querying that also includes a simple '1' or '0' to indicate whether every part is an element of one or many sub-lines; eg (sorry, sure this won't format right):

    Item SubA SubB SubC
    210-1010 1 1 0
    210-1011 1 0 1

    So if choosing SubB in the drop box, I need the autofilter to show the first part, but not the second one. I think I have to do it this way (autofilter) because it will retain all of the parts whether the user is looking at them at this moment or not; they will use this tool to perhaps first price all SubB items, *then* go select SubC and price all of *those* items - and it needs to retain everything they've done, rather than a dynamic query that would lose prior changes and pull in a whole new set of data (if that makes sense).

    So.... I need my autofilter to react not to specifically choosing data on the autofilter itself, but to a choice made in the drop box (probably a macro/VB attached to the box that reacts to the linked cell value that results from the choice, but I don't know how to tell it if the linked cell value is '5', go to column 7 (first two are part number and description) in the autofilter and filter on that column.

    Thanks!!
    Last edited by jwhitwell; 11-14-2008 at 12:53 PM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    An example workbook would help
    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
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    File attached.
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Which column contains bioresorb and which has the 1?

  5. #5
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    The column with the title "Bioresorb" (G). All of the columns have a '1' or a '0' to indicate whether a part (each line) belongs to that product sub-line or not. So some parts in columng G will have a '1', most will have a '0'.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I would use a ComboBox from the Controls tools.

    Set the ListFillRange to the list on sheet2, tip: create a Named Range & use that.

    Then add this code to the ComboBox

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    Thanks - this is giving an error though, "Compile error: Invalid use of Me keyword"...

  8. #8
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    Ok, have found a reference that says this needs to be in a 'class module' rather than standard module because of the 'Me' statement, so have inserted a class module via VB and put this code there - but now can't figure out how to assign it to the combo box. argh. Help? Thanks!

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    It dosn't need a class module. The code should be in the sheet module, the Me refers to the sheet.

    If you right click on the combobox in Design View & select view code you will open the VB Editor, paste the code there.

    Here's an example
    Last edited by royUK; 11-14-2008 at 12:31 PM.

  10. #10
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    Got it, and that's perfect. Which leads to the next unforeseen issue, sorry - After having picked Bioresorb for example, and performed the tasks at hand, the user will then want to use the combo box to pick a different line. Doing so right now simply adds another layer of filter - I need it to first revert to *no filter in place*, and then apply the new filter. Any thoughts/mods to your code that would accomplish that?

    I don't think it can directly unchange the Bioresorb filter specifically (as it really could be filtered on anything), but rather *before* applying the filter you just wrote, it *unapplies* any existing filter in place such that 100% of possible parts are once again displayed, and *then* applies your filter...

    Thanks!

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I thought it was working when a different selection is made. Does this work/

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    07-09-2008
    Location
    Dallas
    MS-Off Ver
    2007
    Posts
    121
    You, sir, are a genius - I believe that does it, thank you *so* much!

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    A pleasure, can you rate the reply?

  14. #14
    Registered User
    Join Date
    03-27-2009
    Location
    Surat,India
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Make autofilter react based upon selection in drop box...

    Can you repost that Sample File. It's Not available for download

    Vishnu


    Quote Originally Posted by royUK View Post
    It dosn't need a class module. The code should be in the sheet module, the Me refers to the sheet.

    If you right click on the combobox in Design View & select view code you will open the VB Editor, paste the code there.

    Here's an example

+ 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