title: Function works for first 2 task but does nothing on the 3rd
body: <p>This is an interesting one.</p>
  
  <p>I have written a function that takes a list of data and separates the list into 2 worksheets. The first contains less than 90 days prior to invoice date and the 2nd contains greater than 90 days prior to invoice date. This function works as expected for the first and second list but for the 3rd list (same format as the other two) it fails to do anything.</p>
  
  <p>The workbook has 7 pages. </p>
  
  <p>Page 2 is the 1st list. Page 3 is the greater than 90 sheet for the 1st list.</p>
  
  <p>Page 4 is the 2nd list. Page 5 is the greater than 90 sheet for the 2nd list.</p>
  
  <p>Page 6 is the 3rd list. Page 7 is the greater than 90 sheet for the 3rd list.</p>
  
  <p>For whatever reason the function works without fail until it is time to work page 6 and 7.</p>
  
  <p>Here is my call to the function:</p>
  
  <pre><code>Call split90(2, first_of_month, inv_wb)
  Call split90(4, first_of_month, inv_wb)
  Call split90(6, first_of_month, inv_wb)
  </code></pre>
  
  <p>the 1st argument is used to define what page is being worked on. The 2nd argument is use to pass the first date for the month. The 3rd argument is used to pass the workbook where the function will be manipulating the list.</p>
  
  <p>Here is the function:</p>
  
  <pre><code>Function split90(start_sheet, first_of_month, inv_wb)
  
      Dim rng_wk As Range
      Dim last_row As Integer
      Dim stop_row As Integer
  
      Debug.Print ("Before last_row: " &amp; inv_wb.Worksheets(start_sheet).Cells(Rows.Count, "C").End(xlUp).Row)
      last_row = inv_wb.Worksheets(start_sheet).Cells(Rows.Count, "C").End(xlUp).Row
      Debug.Print ("After last_row: " &amp; last_row)
      Set rng_wk = inv_wb.Worksheets(start_sheet).Range("C2:C" &amp; last_row)
  
      For Each cell In rng_wk
          If Not IsEmpty(cell.Value) Then
              If CDate(cell.Value) &lt; CDate(first_of_month) - 90 And CDate(cell.Value) &lt;&gt; CDate("1/1/0001") Then
                  stop_row = cell.Row
                  Exit For
              End If
          End If
      Next cell
  
      Set rng_wk = inv_wb.Worksheets(start_sheet).Range("A" &amp; stop_row &amp; ":H" &amp; last_row)
      rng_wk.Cut Destination:=inv_wb.Worksheets(start_sheet + 1).Range("A2")
  
  End Function
  </code></pre>
  
  <p>The above works as expected for list 1 and 2 but when I pass the number 6 for list 3 it just fails. Nothing. No error. Just nothing. All of my testing with <code>Debug.Print()</code> had shown me that for some reason <code>last_row</code> is not getting a value assigned to it when <code>start_sheet</code> is the integer <code>6</code>.</p>
  
  <p>From the above <code>Debug.Print</code> I expect to see the last row of the list printed twice for each call to the function. Instead what I see is the last row printed twice for the first 2 list and only once for the 2nd list. It makes no sense to me.</p>
  
  <p>Here are the results of the print.</p>
  
  <pre><code>Before last_row: 20892
  After last_row: 20892
  Before last_row: 3098
  After last_row: 3098
  Before last_row: 35738
  </code></pre>
  
  <p>As you can see for some reason the variable <code>last_row</code> is not getting assigned a value for the last group... But it is able to see the number before assigning to <code>last_row</code>.</p>