+ Reply to Thread
Results 1 to 13 of 13

AutoFilter Method Of Range Class Failed

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    AutoFilter Method Of Range Class Failed

    Hi all,

    Using Excel 2010.

    I need 2 filter a Range to remove 2 values in the Range: "-" (Accounting zero format) and 00 (left justified as text)

    I receive an AutoFilter Method Of Range Class Failed error message here:
            rngFilter.AutoFilter _
                        Field:=2, _
                        Criteria1:=Array("<>-", "<>00"), _
                        Operator:=xlFilterValues
    The Range definitely exists. Any other thoughts?

    thx
    w
    Kind regards,
    w

    http://dataprose.org

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: AutoFilter Method Of Range Class Failed

    Maybe I am missing it, but I don't see where you specify a range
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: AutoFilter Method Of Range Class Failed

    Thanks gmr4evr1,

    I just did not include it in the snippet as the Range does exist and the problem is with the AutoFilter.

    With ws
    Set rngFilter = .Range(.Cells(6,1),.Cells(6,lngRows))
    End With
    
            rngFilter.AutoFilter _
                        Field:=2, _
                        Criteria1:=Array("<>-", "<>00"), _
                        Operator:=xlFilterValues
    thx
    w

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

    Re: AutoFilter Method Of Range Class Failed

    Why is your column variable called lngRows?
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: AutoFilter Method Of Range Class Failed

    Romperstomper,

    My typo,

    I typed in the code rather than copy paste.
    Should be
    With ws
    Set rngFilter = .Range(.Cells(6,1),.Cells(lngRows,2))
    End With
    
            rngFilter.AutoFilter _
                        Field:=2, _
                        Criteria1:=Array("<>-", "<>00"), _
                        Operator:=xlFilterValues
    I printed the address of the range, came back as $A$6:$B$20

    thx
    w

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

    Re: AutoFilter Method Of Range Class Failed

    Quote Originally Posted by goss View Post
    I typed in the code rather than copy paste.
    Why??

    Anyway, you don't really want an array here:
            rngfilter.AutoFilter _
                        Field:=2, _
                        Criteria1:="<>-", Operator:=xlAnd, Criteria2:="<>00"

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: AutoFilter Method Of Range Class Failed

    goss, Try this one:?

    rngFilter.AutoFilter _
                        Field:=2, _
                        Criteria1:="<>-", Criteria2:="<>00", _
                        Operator:=xlFilterValues
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: AutoFilter Method Of Range Class Failed

    Deleted content as I posted twice

  9. #9
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: AutoFilter Method Of Range Class Failed

    Thanks all,

    None of those option worked. Appears nothing is filtered out.

    I recorded this macro:
    Sub Macro3()
    '
    ' Macro3 Macro
    '
    
    '
        Range("A6:B658").Select
        Range("B658").Activate
        Selection.AutoFilter
        ActiveSheet.Range("$A$6:$B$659").AutoFilter Field:=2, Criteria1:=Array( _
            "-0.01", "0.23", "-0.23", "2.27374E-12"), Operator:=xlFilterValues
    End Sub
    thx
    w

    The broblem being that I never know what the values need to be included, only what should be excluded.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: AutoFilter Method Of Range Class Failed

    odd goss, they filter out on my end when one cell has a - or 00 (or some of each in the list), in column 2. Can you by chance post your book so we can have a look?

    Edit:

    Are you trying to exlude a cell with ONLY 00 or - in the cell, or are you trying to exclude them as part of the data?

  11. #11
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: AutoFilter Method Of Range Class Failed

    Thanks Arkadi,

    Are you trying to exlude a cell with ONLY 00 or - in the cell
    Yes. Sample attached. Cutdown for size. Obfuscated for confidentiality.

    thx
    w
    Attached Files Attached Files

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

    Re: AutoFilter Method Of Range Class Failed

    Try this version:

    Sub Macro1()
        Dim LastRow                     As Long
        Dim n                           As Long
        Dim vKeys
    
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
        With CreateObject("Scripting.Dictionary")
            For n = 7 To LastRow
                Debug.Print Cells(n, "B").Value
                Select Case Cells(n, "B").Text
                    Case "00", "-"
                        ' ignore
                    Case Else
                        .Item(Cells(n, "B").Text) = Empty
                End Select
            Next n
            vKeys = .keys
        End With
        ActiveSheet.Range("A6:B" & LastRow).AutoFilter Field:=2, Criteria1:=vKeys, Operator:=xlFilterValues
    End Sub

  13. #13
    Forum Contributor
    Join Date
    01-07-2004
    Posts
    314

    Re: AutoFilter Method Of Range Class Failed

    Thanks Romper,

    I'm not strong enough with Dictionaries to feel comfortable.
    I ended up replacing zero's and non-numeric with "Blank" and filtering "<>Blank"

    Not great and I think using 2 criteria or criteria array would be faster, but this does work.

    thx
    w

        'Determine rows on retrieve sheet
            lngRowsRetrieve = GetLast(ws:=wsRtrv, _
                                      RC:="r") - 1
                                      
        'Create range for replacements
            With wsRtrv
                Set rngReplace = .range(.Cells(7, 2), .Cells(lngRowsRetrieve, 2))
            End With
    
        'Replace zero's and alpha's
            For Each C In rngReplace
                If C.Value = 0 Or Not IsNumeric(C.Value) Then
                    C.Value = "Blank"
                End If
            Next C
            
        'Create range for filter
            With wsRtrv
                Set rngFilter = .range(.Cells(6, 1), .Cells(lngRowsRetrieve, 2))
            End With
            
        'Filter out "Blank"
            rngFilter.AutoFilter _
                        Field:=2, _
                        Criteria1:="<>Blank", _
                        VisibleDropDown:=True

+ 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 - Yet autofilter works.
    By Carlsbergen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-25-2009, 05:43 PM
  4. AutoFilter method of Range class failed
    By blopreste3180 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-17-2006, 06:45 PM
  5. [SOLVED] 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