+ Reply to Thread
Results 1 to 2 of 2

Cannot set criteria for advanced filter excel vba

  1. #1
    Registered User
    Join Date
    02-14-2009
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    8

    Cannot set criteria for advanced filter excel vba

    I can't set the criteria for a vba advanced filter. I don't get an error on the assignment statement when running the program, but the filter fails, and the watch on the criteria variable says there's an application-defined or object-defined error.

    All the code is in personal.xlsb. Another workbook has all the data, and at the outset, contains a sheet named "Parms" and another sheet named "Registered". Cells H2 and H3 in the Parms sheet contain the criteria for the advanced filter to be applied to the Registered sheet. The H column in Parms looks like this:

    Row 1: FilterCrit ' column header
    Row 2: VoterPct ' Name of the column in Registered that will be filtered. The name is the same on both Parms and Registered
    Row 3: 101 ' The value to filter on

    There is a worksheet variable, ParmSheet, set to Parms. That set is correct, and I can access other parms using it.

    Here's the pertinent code:
    Please Login or Register  to view this content.
    ' I've tried setting the criteria two different way, and get the same error.

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    ' I know H2:H3 is the right range, because I tested it with Test1 = ParmSheet.Cells(2, 8) and Test2 = ParmSheet.Cells(3, 8)

    What am I doing wrong? This code worked when I had the Parms sheet in personal.xlsb, and doesn't now that it's in the same workbook as the Registered file, but I don't know if that's significant. I have triple checked that there is only one column header VoterPct in the Registered sheet, and that both are spelled exactly the same.

    Any help would be appreciated.
    Last edited by alansidman; 10-31-2023 at 11:59 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,895

    Re: Cannot set criteria for advanced filter excel vba

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Guideline #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here.

    I have added them to your post today.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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] Excel 365 - Advanced Filter with Dates Criteria
    By cherias in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-20-2020, 12:48 PM
  3. Excel VBA advanced filter criteria range does not work
    By Distrooooy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2017, 03:30 AM
  4. Replies: 0
    Last Post: 08-04-2017, 02:39 AM
  5. 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
  6. excel 2010 - reasons why advanced filter returns ALL ROWS and not criteria set?
    By wyattea in forum Excel Programming / VBA / Macros
    Replies: 33
    Last Post: 09-13-2013, 08:38 PM
  7. [SOLVED] Wildcards in Advanced filter criteria don't work with Excel 2003
    By Inconceivable in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2005, 10:05 PM

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