title: Procedure works but when turned into a Public Sub to be called it then fails
body: <p>I wrote the following sub:</p>
  
  <pre><code>    Public Sub filterEmployeeSheets(Sheets As Excel.Worksheet, SearchRange As String, Indicator As String, FilterString As String)
  
      'This Sub is used to filter sheets by deleting any rows
      'that do not contain the value stated in variable filterString
  
      '@Parameter Sheets to declare sheet(s) name
      '@Parameter SearchRange to set the column to filter
      '@Parameter Indicator determines the =, &lt;&gt; setting
      '@Parameter FilterString to set the string to keep
  
      Dim lngLr As Long
  
      With Sheets
  
          lngLr = .Cells.Find(What:="*", SearchDirection:=Excel.XlSearchDirection.xlPrevious, SearchOrder:=Excel.XlSearchOrder.xlByRows).Row
  
          If lngLr &gt; 1 Then
              With .Range(SearchRange &amp; lngLr)
                  **.AutoFilter(Field:=1, Criteria1:=Indicator &amp; FilterString)** 'Error is here
                  .EntireRow.Delete()
              End With
          End If
      End With
  End Sub
  
  Public Function ClientSheets(Index As Long) As Excel.Worksheet
  
      'This function indexes all of the Employee sheets
      'to use in various loops during he instal process
      '@param EmployeeSheets, are the sheets to index
  
      Select Case Index
  
          Case 1 : Return xlWSAllEEAnnul
          Case 2 : Return xlWSAllEEHourly
      End Select
  
      Throw New ArgumentOutOfRangeException("Index")
  
  End Function
  </code></pre>
  
  <p>When I call it on the procedure below:</p>
  
  <pre><code>        Dim xlRefSheets As Excel.Worksheet
  
          For i As Long = 1 To 2 Step 1
  
              Dim strOperatorSymbol As String = "&lt;&gt;"
  
              xlRefSheets = ClientSheets(i)
  
              filterEmployeeSheets(xlRefSheets, "K5:K", "&lt;&gt;", "Y")
  
          Next
  
  End Sub
  </code></pre>
  
  <p>I get this error: The command could not be completed by using the range specified. Select a single cell within the range and try the command again. However, If I use the Public Sub as a procedure without the For Loop on a single sheet instead of calling it, it works just fine. </p>