+ Reply to Thread
Results 1 to 6 of 6

Advanced Filter with tables and VBA

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    24

    Advanced Filter with tables and VBA

    Hi

    I trying to write VBA to use advanced filter to get some data from one table to another. I have this code..

    Sheets("Data").ListObjects(1).Range.AdvancedFilter _
    Action:=xlFilterCopy, _
    CriteriaRange:=Sheets("Criteria").Range("A1:A2"), _
    CopyToRange:=Sheets("Query").ListObjects(1).HeaderRowRange, Unique:=False

    But I can't get it to work. Gives me Run time error 1004, AdvancedFilter method of range class failed.

    Would someone be able to show me where I'm going wrong.

    Many thansk

    Max

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,549

    Re: Advanced Filter with tables and VBA

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    09-18-2012
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    24

    Re: Advanced Filter with tables and VBA

    Please see sample file attached. Clicking the button should run the macro and filter the data.
    Attached Files Attached Files

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Advanced Filter with tables and VBA

    I don't think you can do that when the destination is a table (it doesn't seem to work manually either). I'd suggest you make the destination a table after you do the filter.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Registered User
    Join Date
    09-18-2012
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    24

    Re: Advanced Filter with tables and VBA

    Thanks Rory.

    Sadly that's what I thought may be the case.

    Trouble with that though is that I loose the ability to have formulas on the rest of the sheet based on the table or indeed add further calculated columns to the table.

    I thought about making the query destination a range and then copying the data from that range to the table but that does seem like a long way round.

    Max

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,016

    Re: Advanced Filter with tables and VBA

    If you need the table to remain, filter the original data in place, then copy and paste to the table.

+ 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. Reseting multiple tables after advanced filter and/or sort
    By waimea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2018, 05:10 PM
  2. Replies: 0
    Last Post: 08-04-2017, 02:39 AM
  3. VBA Advanced Filter - Two Filters Without Deleting Bottom Filter Data In Same Column Range
    By hysterical.useless in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-14-2017, 02:54 PM
  4. 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
  5. Replies: 5
    Last Post: 12-19-2013, 06:58 AM
  6. advanced filter - button to re apply advanced filter across multiple sheets
    By motmac87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-05-2013, 11:16 PM
  7. advanced filter a range:Advanced Filter function
    By Il Principe in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

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