title: Vba: error Method 'AutoFilterMode' of object '_Worksheet' failed
body: <p>With your help i have this script that: in sheet "ANAF CONTURI" (where i input data) based on a criteria on column G (="DA") it filters and copies the results into a existing sheet named "ANAF BANCI" on a range starting from C2.</p>
  
  <p>Where i input the data i made also a button to execute the macro (its on A1, and on A2 headers).</p>
  
  <p>I get this error when it's trying to remove the filters:</p>
  
  <p><strong>Run-time error '-2147417848 (80010108)':
  Method 'AutoFilterMode' of object '_Worksheet' failed.</strong></p>
  
  <p>and then crashes. (on some exceptions it works fine..without any modifications)</p>
  
  <p>btw: sheet8 is actually "ANAF CONTURI"</p>
  
  <p><strong>This is my code, please help :</strong> </p>
  
  <pre><code>Private Sub CommandButton1_Click()
  ' TRIAZA INFORMATIA INTRODUSA SI O INAINTEAZA SPRE PRELUCRARE IN ANAF BANCI
  Sheet8.Unprotect Password:="online07"
  
  
  Sheets("ANAF BANCI").Range("C2:H1000").ClearContents
  
  
      With Sheets("ANAF CONTURI") '&lt;--| reference your sheet
  
          With .Range("G2", .Cells(.Rows.Count, 1).End(xlUp)) '&lt;--| reference its column "A:G" range from row 1 down to column "A" last not empty row
              .AutoFilter Field:=7, Criteria1:="Da" ''&lt;--| filter referenced range on its 7th column (i.e. column "G") with "Da" values
              If Application.WorksheetFunction.Subtotal(103, .Resize(, 1)) &gt; 1 Then .Resize(.Rows.Count - 1, 6).Offset(1).SpecialCells(xlCellTypeVisible).Copy Destination:=Worksheets("ANAF BANCI").Range("C2")
          End With
          .AutoFilterMode = False
      End With
  
      Sheet8.Range("A3:F20000").Locked = False
      Sheet8.Protect Password:="online07"
  
  End Sub
  </code></pre>