Results 1 to 3 of 3

VBA Error: Runtime Error 1004: AutoFilter method of Range class failed

Threaded View

  1. #1
    Registered User
    Join Date
    10-03-2013
    Location
    Boston, MA
    MS-Off Ver
    Excel 2010
    Posts
    6

    VBA Error: Runtime Error 1004: AutoFilter method of Range class failed

    Hello,

    I'm new to VBA programming, and I'm hoping that someone can help me to pinpoint the root cause of an error message I'm getting. The error message is:

    Runtime Error 1004: AutoFilter method of Range class failed

    I'm trying to duplicate the code of another programmer on a different worksheet. I've pasted the code below and highlighted in red the line of code that is resulting in the error. I've also included the Function code in case there is something I'm missing there.

    Sub FilterFilledData()
        Dim tmpRng As Range
        
        Application.EnableCancelKey = xlDisabled
        strActPred = LCase(Worksheets("Filled").Range("B4"))
        strPos = LCase(Worksheets("Filled").Range("B8"))
        strRegion = LCase(Worksheets("Filled").Range("B5"))
        strArea = LCase(Worksheets("Filled").Range("B6"))
        strDistrict = LCase(Worksheets("Filled").Range("B7"))
        
        'On Error Resume Next
        Worksheets("FilledDetail").Cells.Clear
        'If Err.Number > 0 Then
            'Worksheets.Add
            'ActiveSheet.Name = "FilledDetail"
        'End If
        
        On Error GoTo 0
        Set tmpRng = Worksheets("SCData").Cells(1, 1).CurrentRegion
        
        Worksheets("SCData").AutoFilterMode = False
        
        tmpRng.AutoFilter
        
        If strRegion <> "all" Then
            strfind = "Region"
            colHeading = FindFilledColumnHeadings(strfind)
            tmpRng.AutoFilter Field:=colHeading, Criteria1:=strRegion
        End If
        
        If strArea <> "all" Then
            strfind = "Area"
            colHeading = FindFilledColumnHeadings(strfind)
            tmpRng.AutoFilter Field:=colHeading, Criteria1:=strArea
        End If
        
        If strDistrict <> "all" Then
            strfind = "DSL"
            colHeading = FindFilledColumnHeadings(strfind)
            tmpRng.AutoFilter Field:=colHeading, Criteria1:=strDistrict
        End If
    
        If strActPred <> "all" Then
            strfind = "PredOrActual"
            colHeading = FindFilledColumnHeadings(strfind)
            tmpRng.AutoFilter Field:=colHeading, Criteria1:=strActPred
        End If
    
        If strPos <> "all" Then
            strfind = "Position Simplified"
            colHeading = FindFilledColumnHeadings(strfind)
            tmpRng.AutoFilter Field:=colHeading, Criteria1:=strPos
        End If
        tmpRng.SpecialCells(xlCellTypeVisible).Copy Worksheets("FilledDetail").Range("A1")
        
        Worksheets("FilledDetail").Columns("AH:AR").Delete
        Worksheets("FilledDetail").Columns("AE").Delete
        
            Set tmpRng = Nothing
    End Sub
    
    Function FindFilledColumnHeadings(ByVal strHeading As String) As Integer
        Dim tmpSht As Worksheet
    
        Set tmpSht = Worksheets("SCData")
        
        For i = 1 To tmpSht.Cells(1, 1).End(xlToRight).Column
            If Trim(strHeading) = tmpSht.Cells(1, i) Then
                FindFilledColumnHeadings = i
                Set tmpSht = Nothing
                Exit Function
            End If
        
        Next
    
        FindFilledColumnHeadings = 0
        Set tmpSht = Nothing
    End Function
    Any help anyone can provide is greatly appreciated! I apologize that I may not have pasted the code in a visually-friendly format. This is my first time posting a thread, so hopefully I've provided all the necessary details.

    Thanks!
    Jen
    Last edited by alansidman; 10-03-2013 at 04:36 PM. Reason: code tags added

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Runtime error 1004: Insert method of Range class failed......not sure why
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-21-2011, 02:15 PM
  2. runtime error 1004 pastespecial method of range class failed
    By JillCALIBRE in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-30-2009, 11:31 AM
  3. Error: Runtime 1004 - Select method of range class failed
    By additude in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2008, 05:58 PM
  4. runtime error 1004 pastespecial method of range class failed
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-03-2006, 10:57 AM
  5. [SOLVED] Runtime Error 1004 Select method of Range class Failed
    By IanO in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2005, 04: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