+ Reply to Thread
Results 1 to 24 of 24

Autofilter method of range class failed despite data match existing

  1. #1
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Autofilter method of range class failed despite data match existing

    Hi all,

    The following code is returning the error 'autofilter method of range class failed'. I have defined the IncomeStartDate variable as Range("b19") on my validation sheet which contains a formula to display the value 01/01/2014. If I manually select the custom filter on the sheet in column G (7) using "is after of equal to" 01/01/2014 the sheet filters for those values, so why won't the code replicate this?

    Please Login or Register  to view this content.
    Any help would be greatly appreciated.

    Regards,

    T

  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
    44,425

    Re: Autofilter method of range class failed despite data match existing

    We can't really test your code without some data ... your data ... to test it with.

    Regards, TMS
    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
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Sadly I can't post the data. I have a feeling the problem lies in the formatting so will explore that avenue

  4. #4
    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
    44,425

    Re: Autofilter method of range class failed despite data match existing

    You might find that converting the search item to long, or maybe double, would help given that a date is just a number.

    Regards, TMS

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    Please Login or Register  to view this content.
    returning no value and showing an error are two different things.
    If the code error on this line, it is a syntax error, but if it does not show an error, but does nothing, it may be the code is not recognised the date and becomes a formatting issue.

  6. #6
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    The code error is on this line. But I'm sure there is no syntax error. I will try and upload a sample file as this is driving me crazy

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    If the code errors on that line, it is syntax error.
    Try
    Edited: I did not see you have validation.
    Please Login or Register  to view this content.
    Last edited by AB33; 12-05-2013 at 12:31 PM.

  8. #8
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Hmm, none of the above are working and I cant upload the file. At present the income start date is 01/01/2014. In column 7 of the activeD sheet I have over 5,000 entries beyond this date. They, and their entire row needs to be removed. Can anyone give me a piece of code to do this other than autofilter?

    Thanks in advance

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    It is not working is a vague statement. Did you get the error or not?
    You can probably resolve the issue by looking at

    IncomeStartDate = Validation.Range("B19")

    Go to the module itself, then open local window.
    Step over the code by pressing F8 and see what value do you get when the code reaches this line.
    I suspect the value of IncomeStartDate may be nil.

  10. #10
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Yes I was still getting the error.

    The value of IncomeStartDate was correct. Rather strangely, the code works fine if I use this:

    Please Login or Register  to view this content.
    However I have used the original code:

    Please Login or Register  to view this content.
    Several times before in slightly different circumstances and it has always run smoothly.

    For the moment I will use the "A1:AF1" range but are there any ideas as to why this may have occured?

  11. #11
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    Okay! Try to use a different line.

    Please Login or Register  to view this content.

  12. #12
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Autofilter method of range class failed despite data match existing

    Is the workbook .xls format or later?

  13. #13
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    File is .xlsm

    AB33 your code produces the same error on this line

    Please Login or Register  to view this content.
    It still only runs if I use the "A1:Af1" range as above. Furthermore I have 65,000 rows so the delete method you use is quite lengthy.

    But thank you for all the help so far

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    I used this code hundreds times.
    I am at loss at how you get an error on this line.
    Your cursor has to be on sheet 19 or change this line

    With Worksheets(19)

    I do not know how my code takes long, it is a filter code.
    Okay, the entire row may not be necessary

    Please Login or Register  to view this content.
    Last edited by AB33; 12-05-2013 at 02:06 PM.

  15. #15
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Autofilter method of range class failed despite data match existing

    Do you have a Table or standard range?

  16. #16
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Izandol I have the data in the form of a table query. Not a standard range.

    AB33 I have also used the above code many times. What do you mean my cursor has to be on sheet 19? When I run the code due to the following lines:

    Please Login or Register  to view this content.
    the active sheet is sheet 27 as it is ">100K<60" but that shouldn't matter as I use

    With ActiveD

    Which is linked to sheet 19.

    I've taken your advice with and changed the delete argument and its a little quicker - Thank you

  17. #17
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Autofilter method of range class failed despite data match existing

    You are using sheet index number as a sheet name. It only takes moving one sheet to left or right, to mess-up the order of the sheet index.
    I suggest you should use a string name like sheets("sheet19") or code name of the sheet.
    In this case, you can easily identify the error. If the sheet name (sheet19), does not exist on the sheet collection, you get an error of "Range out of script"

  18. #18
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Ok thanks. I know this is not the error I'm dealing with now but it will definitely avoid confusion in the future!

  19. #19
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Autofilter method of range class failed despite data match existing

    If you have a Listobject you should use Listobjects(1).Range.Autofilter

  20. #20
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Thanks. I don't believe I have a listobject.

  21. #21
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Autofilter method of range class failed despite data match existing

    A Table is a Listobject in VBA.

  22. #22
    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
    44,425

    Re: Autofilter method of range class failed despite data match existing

    Let's face it, without a sample workbook, we're very much in the dark and pretty much wasting everyone's time trying to guess what your issue is.

    You don't have to post the real workbook, just a representative desensitized sample.

    I think it's your choice. Help us to help you.

    Regards, TMS

  23. #23
    Registered User
    Join Date
    10-07-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Autofilter method of range class failed despite data match existing

    Problem solved. I copied the data pasted xlvalues to a new sheet and can now filter using .rows(1) or .range("A:AF") or in any way. I think the problem rested with it being a table.

    Thanks for all the help

  24. #24
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Autofilter method of range class failed despite data match existing

    The problem relates to the combination of a Table and your code which specified a range passing the extent of the table. Stating a range within the table - one or more rows/columns - filters the whole table however it is better to use the Listobject.

+ 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. Autofilter Method of Range Class Failed
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-02-2013, 11:51 AM
  2. Autofilter Method of Range Class Failed
    By goss in forum Excel General
    Replies: 1
    Last Post: 04-05-2012, 11:44 AM
  3. AutoFilter method of Range class failed
    By AdLoki in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2011, 05:30 AM
  4. AutoFilter method of Range class failed - Yet autofilter works.
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2009, 05:43 PM
  5. Autofilter method of range class failed
    By Terry K in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-17-2005, 11: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