+ Reply to Thread
Results 1 to 4 of 4

Advanced Filter Criteria; Copy to another sheet

  1. #1
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Advanced Filter Criteria; Copy to another sheet

    I wish to filter a table and have the results appear on another sheet by VBA, but I would like to know if there is some way to enter the criteria as a formula instead of a range.

    My table is about 15 columns wide, and I wish to filter for all the items in the table column labeled "Key" that are equal to a specified value. I can easily enough start at the target sheet (where I wish the filtered results to appear) and over in cell Z1 label it "Key" (Without quotation marks) and in Z2 enter the key number that will appear in all the records I wish to extract, so the vba for the process would look something like:
    Please Login or Register  to view this content.
    ...but this seems kind of convoluted to me in that I would first have to write the column header and value to Z1 and Z2; it seems we should have a way of telling the CriteriaRange to look for all values in tblPeople[[#Headers],[Key]] that are equal to a value, yet I have not stumbled on the correct syntax if there is one.

    Thoughts?

    Thank-You, Merry Christmas and Happy New Year!!!

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,887

    Re: Advanced Filter Criteria; Copy to another sheet

    As far as I know. Advanced filter requires ranges to be set up prior and I have not found any workaround.

    If you want to do similar operation without criteria range there are several ways to go about it (not Advanced filter).

    1. VBA - ADODB code to retrieve recordset matching criteria and write to new sheet
    2. PowerQuery - To set up criteria, you can... set filter; modify "M" in advanced editor; set up custom "M" function as separate query and pass parameter; set up named ranges to pass parameter etc.
    3. MS Query - Similar to PowerQuery, but all criteria set up either in Editor or via Command Text.
    4. VBA - Autofilter and copy/paste

    Advantage of Advanced Filter is that once you set up criteria range and headers, it's easy for someone without knowledge of VBA or other tools to change parameter directly within workbook. I often combine it with data validation list and small code to allow user to query info (especially when they want to export data without aggregation).

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Advanced Filter Criteria; Copy to another sheet

    The sample code provided by Dennis Wallentin in the Range object help file (https://msdn.microsoft.com/en-us/lib.../ff838238.aspx ) uses advanced filter to create a list of unique values on a second worksheet. You could see if you can modify the code to filter on the criteria you are interested in.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    03-05-2007
    Location
    Falmouth, VA now, Palm Bay, FL for 2 yrs, was Colorado Springs, CO for ten years; Cedark Park, TX; Zeeland, MI; Wilmette, IL; Princeton Junction, NJ; NY, NY
    MS-Off Ver
    365
    Posts
    583

    Re: Advanced Filter Criteria; Copy to another sheet

    Thank-You folks, I'll consider what you have provided and post if I find anything interesting that can be of help to anyone in the future in this regard!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Advanced Filter Code : Criteria Range More Than 1 Row Breaks Filter
    By PaulGW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-10-2021, 04:30 PM
  2. [SOLVED] Filter for Dynamic Fields & Criteria and copy to other sheet
    By Abdur_rahman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-02-2016, 01:21 AM
  3. filter data based on criteria and copy to another sheet
    By anbarasi_r in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2015, 09:56 PM
  4. Filter for Two Criteria and Unique list copy another sheet
    By rr1050 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2014, 10:36 PM
  5. Replies: 8
    Last Post: 05-02-2014, 08:35 AM
  6. Advanced Filter : One Criteria Cell Breaks the Filter - Returns Only Headers
    By PaulGW in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2014, 10:06 AM
  7. Advanced filter with some conditions & copy filtered value to next sheet
    By sudhirkumar3429 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-24-2012, 05:46 AM

Tags for this Thread

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