title: What to do when autofilter in VBA returns no data?
body: <p>I am trying to filter a range of values and based on my criteria, at times I might have no data that fits my criteria. In that case, I do not want to copy any data from the filtered data. If there is filtered data, then I would like to copy it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>With Workbooks(KGRReport).Worksheets(spreadSheetName).Range("A1:I" &amp; lastrowinSpreadSheet)
      .AutoFilter Field:=3, Criteria1:=LimitCriteria, Operator:=xlFilterValues 'Do the filtering for Limit
       .AutoFilter Field:=9, Criteria1:=UtilizationCriteria, Operator:=xlFilterValues 'Do the filtering for Bank/NonBank
  End With
  
  'Clear the template
   Workbooks(mainwb).Worksheets("Template").Activate
   Workbooks(mainwb).Worksheets("Template").Rows(7 &amp; ":" &amp; Rows.Count).Delete
  
   'Copy the filtered data
   Workbooks(KGRReport).Activate
   Set myRange = Workbooks(KGRReport).Worksheets(spreadSheetName).Range("B2:H" &amp; lastrowinSpreadSheet).SpecialCells(xlVisible)
   For Each myArea In myRange.Areas
       For Each rw In myArea.Rows
             strFltrdRng = strFltrdRng &amp; rw.Address &amp; ","
       Next
   Next
  
   strFltrdRng = Left(strFltrdRng, Len(strFltrdRng) - 1)
   Set myFltrdRange = Range(strFltrdRng)
   myFltrdRange.Copy
   strFltrdRng = ""
  </code></pre>
  
  <p>It is giving me an error at </p>
  
  <pre><code>Set myRange = Workbooks(KGRReport).Worksheets(spreadSheetName).Range("B2:H" &amp; lastrowinSpreadSheet).SpecialCells(xlVisible)
  </code></pre>
  
  <p>When there is no data at all, it is returning an error: "No cells found".</p>
  
  <p>Tried error handling like this post: <a href="https://stackoverflow.com/questions/25380886/1004-error-no-cells-were-found-easy-solution">1004 Error: No cells were found, easy solution?</a></p>
  
  <p>But it was not helping. Need some guidance on how to solve this.</p>