+ Reply to Thread
Results 1 to 7 of 7

Returning all rows from table that match certain criteria

  1. #1
    Registered User
    Join Date
    11-10-2009
    Location
    Mass
    MS-Off Ver
    Excel 2007
    Posts
    4

    Returning all rows from table that match certain criteria

    I need to retrieve information from multiple rows in a table based on certain criteria (date compared to today's date, existence of "no" in a column).

    Problem and solution I would like attached. Many thanks.
    Attached Files Attached Files
    Last edited by carbonn; 11-11-2009 at 06:18 PM. Reason: solved

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Returning all rows from table that match certain criteria

    Your sheet indicates you want this to be going on "automatically", so I would think a macro would be the way to go. Is VBA ok?

    Here are two versions of a macro that will do what you want based on moving that data back up to A1 as the starting point, like normal.

    Please Login or Register  to view this content.
    This macro goes into the sheet module itself, so just by bringing the sheet up onscreen, the Overdue report updates itself.
    How to install the sheet macro:

    1. Open up your workbook
    2. Right-click on the OVERDUE sheet tab and select View Code
    3. Copy and Paste in your code (given above)
    4. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Simply move to another sheet, then return to the OVERDUE sheet and it will update.

    ==========
    Please Login or Register  to view this content.
    This version is a standalone macro that goes in a regular module and can be run from the macro menus. How to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save your sheet

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-10-2009
    Location
    Mass
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Returning all rows from table that match certain criteria

    VBA is fantastic, do you think that this could be done with some combination of index/vlookup/match? I am not up to speed with these yet.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Returning all rows from table that match certain criteria

    Yes it can. In fact I'm glad you asked. I didn't look at your "desired results" section very carefully, did I? Sorry about that...the index/match technique is actually well suited to this task.

    I added a "key column" to the data sheet so that it can flag the overdue items in an easy sequential way. You can hide that column if you find it unsightly.

    On the OverDue page, we then index/match those key rows into the table and do the required math on the last column.
    Attached Files Attached Files
    Last edited by JBeaucaire; 11-11-2009 at 01:13 PM.

  5. #5
    Registered User
    Join Date
    11-10-2009
    Location
    Mass
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Returning all rows from table that match certain criteria

    It's a thing of beauty - will take me a few minutes (!) to work out why it works, but it does, and much quicker than the VBA - especially as my sparklines macro seemed to really slow it down - presumably it was running every time something changed on the page as well.

    Many thanks.

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Returning all rows from table that match certain criteria

    You didn't mention you had other sheet-level macros active on that sheet. Yes, the macros would interfere with each other unless you specifically tell the active macro to suppress others.

    To do that, you add these lines of code to the top and bottom of the macro:
    Please Login or Register  to view this content.
    Using that, your macros will always trigger independently and execute quickly.

  7. #7
    Registered User
    Join Date
    11-10-2009
    Location
    Mass
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Returning all rows from table that match certain criteria

    Yes, I didn't know either (not my macros). I've been removed from macros long enough to be dangerous but to completely forget about how the nuances work.

    Thanks for the advice.

+ 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