+ Reply to Thread
Results 1 to 6 of 6

run time error 1004 autofilter method of range class failed

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2021
    Location
    Romania
    MS-Off Ver
    Office 2010
    Posts
    5

    run time error 1004 autofilter method of range class failed

    Hello, need some ideas? i have this code and it was perfect but i have some errors? and I don?t understand why.
    This is the code:
    Private Sub Worksheet_Activate()
     
        Dim UR As Range
    
        Set UR = Sheets("Urmarire 2022").UsedRange
        Sheets("Restante").Cells.ClearContents
        UR.AutoFilter 16, "<" & CDbl(Date + 3) ' here i have this error: run time error 1004 autofilter method of range class failed
        UR.AutoFilter 15, ""
        UR.SpecialCells(xlCellTypeVisible).Copy Sheets("Restante").Cells(1, 1)
        UR.AutoFilter
        
         For x = 1 To Cells(Rows.Count, "p").End(xlUp).Row
            If Cells(x, 16) < Date Then
                Cells(x, 16).Interior.Color = vbRed
            End If
        Next x
        
    
        
    End Sub

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: run time error 1004 autofilter method of range class failed

    That's because you have no data in columns P:Q (15:16) and no other data beyond those columns. In this case you be trying to filter a range outside "Sheets("Urmarire 2022").UsedRange".
    Add a MsgBox here just to see what I mean:
    Set UR = Sheets("Urmarire 2022").UsedRange
    MsgBox "Usedrange = " & UR.Address             '<- added for debugging
    Sheets("Restante").Cells.ClearContents
    Last edited by rollis13; 09-07-2022 at 10:51 AM.

  3. #3
    Registered User
    Join Date
    12-09-2021
    Location
    Romania
    MS-Off Ver
    Office 2010
    Posts
    5

    Re: run time error 1004 autofilter method of range class failed

    MesBox say " Usedrange = $A$1:$P$5163..... any ideas why not working?
    Last edited by 07avr; 09-08-2022 at 02:36 AM.

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: run time error 1004 autofilter method of range class failed

    Sorry, no other idea, a valid UsedRange exists so I don't see any other reason why your macro could go wrong.
    Maybe if you attach a dummy 'not working' file (just a few rows of data).

  5. #5
    Registered User
    Join Date
    12-09-2021
    Location
    Romania
    MS-Off Ver
    Office 2010
    Posts
    5

    Re: run time error 1004 autofilter method of range class failed

    i found the problem.... it is set filter in first sheet ... if i remove filter in first sheet the code it`s great again

  6. #6
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: run time error 1004 autofilter method of range class failed

    Well done .

+ 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] Run time error 1004: Autofilter method of range class failed in personal macro workbook.
    By Asad Mir in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-24-2020, 02:04 PM
  2. [SOLVED] Macro Error on Filtering – “Run-time error ‘1004’ Autofilter method of range class failed
    By kschmit1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2019, 11:49 AM
  3. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  4. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  5. Run-time error '1004' ; AutoFilter Method of Range class failed
    By ESMAMAF in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-18-2012, 06:30 PM
  6. Run Time Error 1004: Autofilter method of range class failed
    By HP RodNuclear in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2010, 05:37 PM
  7. Run-time error '1004' ; AutoFilter Method of Range class failed
    By BorisMKD in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 10-20-2008, 05:47 AM

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