Error 1004: AutoFilter method of Range Class Failed

Nlhicks

Active Member
Joined
Jan 8, 2021
Messages
264
Office Version
  1. 365
Platform
  1. Windows
This code was working perfectly and now it is not. I have not changed anything on my template and all of a sudden it is giving me this error. Any ideas?


VBA Code:
Sub FindRightRow1()

    Dim Rowz As Integer
    Dim wb As Workbook
    Dim wbMaster As Workbook
    Dim wsLinesMaster As Worksheet
    Dim wbUpdate As Workbook
    Dim wsFacility As Worksheet
    Dim sValue As String, tValue As String, uValue As String
    Dim strFile As String
    Dim strWbVersion As String
    Dim Rng1 As Range, Rng2 As Range, myRange As Range
    Dim StorRng As Variant
    Dim SearchCell As Integer
 
  '//// adjust the path to match, this is my sample for testing \\\'
    Const cstrPath As String = "C:\Users\nhicks\Documents\Ratings\Saved Versions\"
    Const cstrStFileName As String = "WAPA-UGPR Facility Rating and SOL Record (Data File)_v"
    Const cstrwbMaster As String = "WAPA-UGPR Facility Rating and SOL Record (Master).xlsm"
    Const cstrMasterUpdate As String = "Line Update"
    Const cstrShFacility As String = "Facility Ratings & SOLs (Lines)"

  '/// will find any xls, xlsb, xlsx or xlsm workbook that start with cstrStFileName
  '/// and should deliver the highest number from there
  strWbVersion = HighestVersion(cstrPath, ".xlsm", cstrStFileName)
  If Len(strWbVersion) = 0 Then
    MsgBox "Could not spot a version of " & vbCrLf & cstrStFileName & _
        vbCrLf & "in Path " & cstrPath, vbInformation, cstrMsgTitle
    GoTo end_here
  End If

  For Each wb In Workbooks
    If LCase(wb.Name) = LCase(cstrwbMaster) Then
      Set wbMaster = wb
      Exit For
    End If
  Next wb
  If wbMaster Is Nothing Then
    If Dir(cstrwbMaster) <> "" Then
      Set wbMaster = Workbooks.Open(cstrwbMaster)
    Else
      MsgBox "Could not find '" & cstrwbMaster & "' in current folder. Please open workbook and start again.", vbInformation, cstrMsgTitle
      GoTo end_here
    End If
  End If
  If Evaluate("ISREF('[" & cstrwbMaster & "]" & cstrMasterUpdate & "'!A1)") Then
    Set wsLinesMaster = wbMaster.Sheets(cstrMasterUpdate)
  Else
    MsgBox "Sheet '" & cstrMasterUpdate & "' not found in workbook '" & cstrwbMaster, vbInformation, cstrMsgTitle
    GoTo end_here
  End If
  
  For Each wb In Workbooks
    If LCase(wb.Name) = LCase(strWbVersion) Then
      Set wbUpdate = wb
      Exit For
    End If
  Next wb
  If wbUpdate Is Nothing Then
    If Dir(IIf(Right(cstrPath, 1) = "\", cstrPath, cstrPath & "\") & strWbVersion) <> "" Then
      Set wbUpdate = Workbooks.Open(IIf(Right(cstrPath, 1) = "\", cstrPath, cstrPath & "\") & strWbVersion)
    Else
      MsgBox "Could not find '" & strWbVersion & "' in " & cstrPath & ". Please open workbook and start again.", vbInformation, cstrMsgTitle
      GoTo end_here
    End If
  End If
  If Evaluate("ISREF('[" & strWbVersion & "]" & cstrShFacility & "'!A1)") Then
    Set wsFacility = wbUpdate.Sheets(cstrShFacility)
  Else
    MsgBox "Sheet '" & cstrShFacility & "' not found in workbook '" & strWbVersion, vbInformation, cstrMsgTitle
    GoTo end_here
  End If

  Application.ScreenUpdating = False

    With wsFacility
    If wsLinesMaster.Range("D5").Value <> "" Then
      .Range("A1").CurrentRegion.AutoFilter field:=10, Criteria1:="*" & wsLinesMaster.Range("D5") & "*"
    End If
    If wsLinesMaster.Range("D6").Value <> "" Then
      .Range("A1").CurrentRegion.AutoFilter field:=11, Criteria1:="*" & wsLinesMaster.Range("D6") & "*"
    End If
    If wsLinesMaster.Range("D7").Value <> "" Then
      .Range("A1").CurrentRegion.AutoFilter field:=37, Criteria1:="" & wsLinesMaster.Range("D7") & ""
    End If
    
        Rowz = Application.WorksheetFunction.Subtotal(3, .Range("A2:A" & .Cells(.Rows.Count, "A").End(xlUp).Row))
            Debug.Print Rowz
        If Rowz <= 1 Then
            wsLinesMaster.Range("C11").Value = .Range("B2:B695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C12").Value = .Range("C2:C695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C13").Value = .Range("D2:D695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C14").Value = .Range("E2:E695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C15").Value = .Range("F2:F695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C16").Value = .Range("G2:G695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C17").Value = .Range("H2:H695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C18").Value = .Range("I2:I695").SpecialCells(xlCellTypeVisible)
        
            If IsEmpty(Range("C11")) Then
                Call Reverse
            End If
    
        ElseIf Rowz > 1 Then
            GoSub Item_Open
            .Range("A1").CurrentRegion.AutoFilter field:=36, Criteria1:=wsLinesMaster.Range("H6")
            wsLinesMaster.Range("C11").Value = .Range("B2:B695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C12").Value = .Range("C2:C695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C13").Value = .Range("D2:D695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C14").Value = .Range("E2:E695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C15").Value = .Range("F2:F695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C16").Value = .Range("G2:G695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C17").Value = .Range("H2:H695").SpecialCells(xlCellTypeVisible)
            wsLinesMaster.Range("C18").Value = .Range("I2:I695").SpecialCells(xlCellTypeVisible)

    End If

end_here:
  Set wsLinesMaster = Nothing
  Set wsFacility = Nothing
  Set wbUpdate = Nothing
  Set wbMaster = Nothing
  Application.ScreenUpdating = True
  Exit Sub

Item_Open:
  sValue = Application.InputBox("Enter the TO: Bus Number here, Thank you.")
  wsLinesMaster.Range("H6").Value = sValue
  Debug.Print sValue
  Return

End With


End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Many times that happens due to a data or structure change.
If you hit "Debug" when that message shows up, which line of code does it highlight?
 
Upvote 0
VBA Code:
 .Range("A1").CurrentRegion.AutoFilter field:=10, Criteria1:="*" & wsLinesMaster.Range("D5") & "*"
 
Upvote 0
VBA Code:
 .Range("A1").CurrentRegion.AutoFilter field:=10, Criteria1:="*" & wsLinesMaster.Range("D5") & "*"
OK, please answer the following questions:

1. How many rows of data are on the sheet being filtered?
2. What is the value in Cell D5 of the wsLineMaster sheet?
3. Do you have any any values in column J of the data being filtered that match the value listed in item #2?
 
Upvote 0
Solution
I figure this out, I ruined my own code by adding a column to my spreadsheet which broke it. Thank you
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top