+ Reply to Thread
Results 1 to 3 of 3

Advanced Filter Macro (only returns column headings)

  1. #1
    Registered User
    Join Date
    08-05-2011
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    2

    Advanced Filter Macro (only returns column headings)

    Hello all, 1st time poster so please be patient with me.

    I was wondering if anyone could help me solve an issue I'm having with creating a macro to filter some data from one sheet to another. I used the "record a macro" function to get the code I've posted below but when I run the macro, it only gives me headings of the columns in the "Inputs" sheet .

    In my workbook I have a main sheet called "Inputs" and another sheet called "Sheet1". The code below works when I manually apply an advanced filter (Data>> Advanced>>Ok) but does not do what I need it to do when I run the macro.

    I have created Named Ranges entitled "Data", "Criteria" and "Extract"

    Please Login or Register  to view this content.
    I checked this against a 2nd macro in which I didn't use the named ranges. Again the same result: When I apply the advanced filter manually, it works. When I run the filter from the macro, it gives me the headings of the columns in the "Inputs" tab.

    Please Login or Register  to view this content.

    I would like an amendment to the above macos that will allow the correct data to be displayed for the relevant criteria. I know I've probably left something basic out, but I just can't figure out what despite trawling through forums and comparing other peoples codes to mine. Any help would be greatly appreciated.

    My thanks in advance
    Nick
    Attached Files Attached Files
    Last edited by Mufasta; 08-06-2011 at 11:54 AM.

  2. #2
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007, 2010, 2013
    Posts
    1,252

    Re: Advanced Filter Macro (only returns column headings)

    Hi,

    Change the criteria range formulae to this:

    A8: =IF(D2<G2,">="&D2, "Dates")
    B8: =IF(G2>D2, "<=" &G2, A8)


    Then your code could be revised to this:
    Please Login or Register  to view this content.
    The Sheet5.Select line is necessary. When you're automating the advanced filter, the CopyToRange must be on the active sheet, so this is one of those rare occasions when selecting a sheet is required.
    Hope that helps,

    Colin

    RAD Excel Blog

  3. #3
    Registered User
    Join Date
    08-05-2011
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Advanced Filter Macro (only returns column headings)

    Hi Colin,

    This worked like a treat. Thanks once again.

    Kind regards
    Nick

+ 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