title: Autofilter Returns no rows but so the visible range is nothing but the Filtered Visible Range is not nothing
body: <p>So this is the relevant part of the code:</p>
  <pre><code>i = Feuil1.Cells.Rows.count
  
  i = Feuil1.Cells(i, 1).End(xlUp).Row
  j = Feuil1.Cells(1, 1).End(xlToRight).Column
  HelpAddress = Feuil1.Cells(i, j).Address
  
  Set Table = Feuil1.ListObjects(&quot;FiltersTable&quot;)
  
  HelpArr = Application.WorksheetFunction.Transpose(Table.ListColumns(&quot;Rubriques&quot;).DataBodyRange)
  HelpArr2 = Application.WorksheetFunction.Transpose(Table.ListColumns(&quot;Departements&quot;).DataBodyRange)
  HelpArr = UniqueNoEmpty(HelpArr)
  HelpArr2 = UniqueNoEmpty(HelpArr2)
  
  For i = LBound(HelpArr2) To UBound(HelpArr2)
      HelpArr2(i) = CStr(HelpArr2(i)) &amp; &quot;*&quot;
  Next i
  
  FilterArray2 = Array(&quot;*@*&quot;)
  
  Set Wbk = Workbooks.Add
  Set Ws = Wbk.Worksheets(1)
  Feuil1.Activate
  Feuil1.Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; Feuil1.Cells(1, j).Address).Copy
  Ws.Cells(1, 1).PasteSpecial xlPasteValues
  
  For Each Rubrique In HelpArr
      
      FilterArray = Array(Rubrique &amp; &quot;*&quot;)
      
      With Feuil1
          On Error Resume Next
          .ShowAllData
          On Error GoTo 0
  '        .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=11
          .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=11, Criteria1:=FilterArray, Operator:=xlFilterValues
          .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=9, Criteria1:=FilterArray2, Operator:=xlFilterValues
  '        .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4, Criteria1:=FilterArray3, Operator:=xlFilterValues, Operator:=xlOr
      End With
      
      For i = LBound(HelpArr2) To UBound(HelpArr2)
          
          Feuil1.Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4
          Feuil1.Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4, Criteria1:=HelpArr2(i), Operator:=xlFilterValues
          Set FilteredRng = Feuil1.Range(&quot;A2&quot; &amp; &quot;:&quot; &amp; HelpAddress).SpecialCells(xlCellTypeVisible)
          
          If Not FilteredRng Is Nothing Then
              FilteredRng.Copy
              Set HelpRng = Ws.Cells(Ws.Cells.Rows.count, 1).End(xlUp)
              Do While HelpRng.Value &lt;&gt; &quot;&quot;
                  Set HelpRng = HelpRng.Offset(1, 0)
              Loop
              Ws.Range(HelpRng.Address).PasteSpecial xlPasteValues
          End If
          
      Next i
      
  Next Rubrique
  </code></pre>
  <p>The first line in Feuil1 is the row with the headers with filters.</p>
  <p>The thing is that when the Criteria1 gives no rows as result, and so the only visible row is the row with the filters, in that case the visible range is nothing BUT <code>FilteredRng is Nothing</code> gives False as result because for some reason FilteredRng is actually the first row with the filters.</p>
  <p>I can't understand how this happens because the first row was not part of the range to begin with.</p>
  <p>Furthermore it prevents me from catching the error using <code>if FilteredRng is Nothing then</code></p>
  <p>Now the workaround for this is <code>if FilteredRng.rows.count = 1 and FilteredRng.row=1 then</code> but still I'd like to be able to catch the error by comparing with Nothing as the filter row / header row might change rows in different cases... and I have pre-built functions and subs that are for general case use where I compare to Nothing.</p>
  <p>If anyone knows what's going on here or how to catch the 'No cells found' error I would really appreciate it.</p>
  <p><strong>UPDATE:</strong></p>
  <p>After updating the code following Rory's comments this is how the code looks like now:</p>
  <pre><code>On Error Resume Next
  Feuil1.ShowAllData
  On Error GoTo 0
  
  i = Feuil1.Cells.Rows.count
  
  i = Feuil1.Cells(i, 1).End(xlUp).Row
  j = Feuil1.Cells(1, 1).End(xlToRight).Column
  HelpAddress = Feuil1.Cells(i, j).Address
  
  Set Wbk = Workbooks.Add
  Set Ws = Wbk.Worksheets(1)
  Feuil1.Activate
  Feuil1.Range(&quot;A1:&quot; &amp; Feuil1.Cells(1, j).Address).Copy
  Ws.Cells(1, 1).PasteSpecial xlPasteValues
  
  Set Table = Feuil1.ListObjects(&quot;FiltersTable&quot;)
  
  HelpArr = Application.WorksheetFunction.Transpose(Table.ListColumns(&quot;Rubriques&quot;).DataBodyRange)
  HelpArr2 = Application.WorksheetFunction.Transpose(Table.ListColumns(&quot;Departements&quot;).DataBodyRange)
  HelpArr = UniqueNoEmpty(HelpArr)
  HelpArr2 = UniqueNoEmpty(HelpArr2)
  
  For i = LBound(HelpArr2) To UBound(HelpArr2)
      HelpArr2(i) = CStr(HelpArr2(i)) &amp; &quot;*&quot;
  Next i
  
  FilterArray2 = Array(&quot;*@*&quot;)
  
  For Each Rubrique In HelpArr
      
      FilterArray = Array(Rubrique &amp; &quot;*&quot;)
      
      With Feuil1
          On Error Resume Next
          .ShowAllData
          On Error GoTo 0
  '        .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=11
          .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=11, Criteria1:=FilterArray, Operator:=xlFilterValues
          .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=9, Criteria1:=FilterArray2, Operator:=xlFilterValues
  '        .Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4, Criteria1:=FilterArray3, Operator:=xlFilterValues, Operator:=xlOr
      End With
      
      For i = LBound(HelpArr2) To UBound(HelpArr2)
          
          Set FilteredRng = Nothing
          Feuil1.Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4
          Feuil1.Range(&quot;A1&quot; &amp; &quot;:&quot; &amp; HelpAddress).AutoFilter Field:=4, Criteria1:=HelpArr2(i), Operator:=xlFilterValues
          On Error Resume Next
          Set FilteredRng = Feuil1.Range(&quot;A2&quot; &amp; &quot;:&quot; &amp; HelpAddress).SpecialCells(xlCellTypeVisible)
          On Error GoTo 0
          
          If Not FilteredRng Is Nothing Then
  '        If FilteredRng.Rows.count = 1 And FilteredRng.Row = 1 Then
              FilteredRng.Copy
              Set HelpRng = Ws.Cells(Ws.Cells.Rows.count, 1).End(xlUp)
              Do While HelpRng.Value &lt;&gt; &quot;&quot;
                  Set HelpRng = HelpRng.Offset(1, 0)
              Loop
              Ws.Range(HelpRng.Address).PasteSpecial xlPasteValues
          End If
          
      Next i
      
  Next Rubrique
  </code></pre>