title: Integer not storing correct LastRow value after many loops: VBA Run-Time error
body: <p>In the code below, my <code>LastRow</code> variable is not storing the right row number on the 27th loop (<code>i = 27</code>) causing the code to malfunction</p>
  
  <p>I have used the F8 step through multiple times and noticed that the issue is on the 27th loop. The <code>LastRow</code> variable is meant to be +1204 rows from the previous <code>LastRow</code> value on each iteration of the loop, so I was expecting <code>LastRow = 32509</code> instead of <code>LastRow = 31316</code>. For reference, on the 26th loop, <code>LastRow = 31305</code>. I'm not sure why the it is finding the wrong <code>LastRow</code> when the code has worked for the first 26 loops.</p>
  
  <p>I am trying to get from my Source Table to my Desired Table:</p>
  
  <p><strong><em>Source Table</em></strong>
  <a href="https://i.stack.imgur.com/Skv3m.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Skv3m.png" alt="enter image description here"></a></p>
  
  <p>to </p>
  
  <p><strong><em>Desired Table</em></strong></p>
  
  <p><a href="https://i.stack.imgur.com/PEQkE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PEQkE.png" alt="enter image description here"></a></p>
  
  <p>Also , the final error that shows is: </p>
  
  <blockquote>
    <p>Run-Time error '1004': Application -defined or object- defined error </p>
  </blockquote>
  
  <pre><code>Sub Populate_entity()        
  Dim i As Integer    
  i = 1    
  Dim LastRow  As Long
  Dim SearchText As String   
  
  Do While i &lt; 122 ' go across entity (columns wise)    
      If i = 1 Then   
          Range("E1").Select    
          Selection.Copy                                 
          SearchText = ActiveCell.Value
          ActiveCell.End(xlToLeft).Select                 'snap to left (cell A1)
          ActiveCell.Offset(0, 2).Select                  'move to cell C1
          ActiveCell.Offset(1, 0).Select                   ' move to cell C2
      Else            
          ActiveCell.Offset(0, i + 1).Select    
          Selection.Copy
          SearchText = ActiveCell.Value
          ActiveCell.End(xlToLeft).Select
          ActiveCell.Offset(0, 2).Select
          ActiveCell.End(xlDown).Select
          ActiveCell.Offset(1, 0).Select            
      End If                
      ActiveSheet.Paste
      ActiveCell.Offset(1203, 0).Select        
      ActiveSheet.Paste
      ActiveCell.End(xlUp).Select
      ' ======== Error here ========
      LastRow = Cells.Find(What:=SearchText, After:=ActiveCell, LookIn:=xlValues, SearchOrder:=xlByRows).Row
      Range("C" &amp; ActiveCell.Row &amp; ":C" &amp; LastRow).FillDown
      ActiveCell.End(xlUp).Select       
      i = i + 1    
  Loop    
  End Sub
  </code></pre>