+ Reply to Thread
Results 1 to 5 of 5

Advanced Filter works manually but not in VBA?

  1. #1
    Registered User
    Join Date
    06-27-2006
    Posts
    9

    Advanced Filter works manually but not in VBA?

    Hello,

    I have setup an advanced filter that is extremely temperamental, the problem seems to be that it ignores the criteria range when the code is read in VBA. The advanced filter code is stored in Module1 and the code is called by a command button on a worksheet. I can get the filter to recognise the criteria if I go through the advanced filter tool on the toolbar OR if I step through the exact same vba code using F8. However it doesn’t recognise the criteria and the advanced filter does not work properly if I call the code from the command button on the worksheet. I’ve read that this has happened before but I’m stumped as how to sort it out. I’m using excel 2007 in compability mode with 2003, and the exact same thing happens in 2003.

    Has anyone got any ideas why this might be the case?

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Advanced Filter works manually but not in VBA?

    Hi,

    Difficult to be certain without seeing the workbook in question, but I'd hazard a guess that you are not fully referencing the criteria range. This is often the cause of a macro working when you step through it but not otherwise since the tendency when stepping through is to keep jumping back to Excel to see what's happening on the active sheet.

    Try referencing your criteriarange with a fill workbook/sheet/range reference.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-28-2009
    Location
    Lausanne, CH
    MS-Off Ver
    2007 / 2010 beta
    Posts
    5

    Question Re: Advanced Filter works manually but not in VBA?

    Hi, I'm a newbie to the forum, but not to Excel.

    I seem to have the same problem as rob0r. I record a macro for an advanced filter with copy to another location. While recording the filter works, but as soon as I run the recorded macro, the only things that happen is the creation of two named fields ("Criteria" and "Extract") and the header line of the extracted data at the new location is written.

    I think it's not due to the reference as suggested by Richard Buttrey (because I did the same macro recording with a small data set (12 lines x 3 rows) and here the execution works as wanted ), but probably to the size of the original data set (43'600 lines x 27 rows). Could that be reason?

    If needed I can send the file. Any help is very much appreciated. Thank you in advance.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Advanced Filter works manually but not in VBA?

    Hi,

    Welcome to the forum.

    You would be better advised to start a new thread of your own - please see the forum rules, in particular rule 2.

    This is for your own benefit and you're likely to receive a larger response since more people look at original threads than look at already established threads.

    By all means also post a link to this thread.

    Kind regards

  5. #5
    Registered User
    Join Date
    11-28-2009
    Location
    Lausanne, CH
    MS-Off Ver
    2007 / 2010 beta
    Posts
    5

    Re: Advanced Filter works manually but not in VBA?

    Ok, thank you Richard. I did open a new thread here.

+ 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