title: VBA loop conditional stops being evaluated after arbitrary number of lines
body: <p>Here is my code. The code itself seems to work but for some reason the conditional statement stops after line 32645. I tried switching all variables to Long, didn't help.</p>
  
  <p>Also, the code works if I make it start at line 32646, but then stops at a random later line (~18000). There seem to be no similarities in the data it stops at. Originally I tried a for loop specifying the start and end row but that didn't work either so I tried the while loop (both theoretically should work but neither seems to ).</p>
  
  <p>It needs to be able to process 130,000 + lines, any idea why this might be happening ?</p>
  
  <p><strong>The Problem</strong>    </p>
  
  <p>The loop stops running without error and by adding a messagebox I know my row incrementing variable ends up at the last row, but depending on the workbook, the conditional statements stop being evaluated after an arbitrary number of lines.</p>
  
  <p>If I run the script starting at the line below where the first run stopped, it works but again for a (possibly different) arbitrary number of steps. </p>
  
  <p><em>Notes</em></p>
  
  <p>I have made all my variables "Long" type. I used Option Explicit. </p>
  
  <pre><code>data_row = CLng(InputBox("Please enter the row number of the first data entry"))
  Worksheets.Add(After:=Worksheets(1)).name = "Formatted_Output"
  
  Set ws = Sheets("Formatted_Output")
  Worksheets(1).Activate
  LastCol = ActiveSheet.UsedRange.Columns(ActiveSheet.UsedRange.Columns.Count).Column
  LastRow = ActiveSheet.UsedRange.Rows(ActiveSheet.UsedRange.Rows.Count).row
  data_col = LastCol
  
   'loop through entries to get account and permissions
   increment = data_row
   Do Until increment = LastRow
      If Cells(data_row, data_col) = "" Then
          data_col = data_col - 1
      Else
     ' ~&gt; For illegal ==&gt; access denied permission that throws errors
          If Cells(data_row, data_col).Value = "==&gt;access denied" Then
              permissions = "access denied" 'remove illegal =
              ws.Cells(output_row, 3).Value = permissions 'print permissions to output file
          Else
              permissions = Cells(data_row, data_col).Value 'cell should be permission cell of each row
              ws.Cells(output_row, 3).Value = permissions 'print permissions to output file
          End If
  
          data_col = data_col - 1 'domain / account cell is now highlighted
  
          If InStrRev(Cells(data_row, data_col).Value, "?") &gt; 0 Then
  
              account = Split(Cells(data_row, data_col).Value, "?")(1) &amp; Str(unknown_count) ' separate domain name and unknown id
              unknown_count = unknown_count + 1 ' counting the number of unkown accounts found
              ws.Cells(output_row, 2) = account 'print unknown account Id to output
  
              domain_bit = Split(Cells(data_row, data_col).Value, "?")(0) '' get separate domain name from id cell
              data_col = data_col - 1 'domain second from end cell is now highlighted
  
              Do While data_col &gt; 0 'generate domain from rest of row
                  domain_bit = Cells(data_row, data_col).Value &amp; domain_bit 'domain built backwards
                  data_col = data_col - 1 'check next column for more of location name
              Loop
  
              ws.Cells(output_row, 1) = domain_bit
                  'data_col = LastCol
                  'data_row = data_row + 1
                  'output_row = output_row + 1
  
          ElseIf InStrRev(Cells(data_row, data_col).Value, "\") &gt; 0 Then
  
              account = Split(Cells(data_row, data_col).Value, "\")(1) 'separate account ID
              ws.Cells(output_row, 2) = account 'print account ID to oputput
  
              domain_bit = Split(Cells(data_row, data_col).Value, "\")(0)
              data_col = data_col - 1 'domain second from end cell is now highlighted
  
              Do While data_col &gt; 0 'generate domain from rest of row
                  domain_bit = Cells(data_row, data_col).Value &amp; domain_bit 'domain built backwards
                  data_col = data_col - 1 'check next column for more of location name
              Loop
  
              ws.Cells(output_row, 1) = domain_bit 'output to file
  
          Else
                           account = Cells(data_row, data_col).Value 'account is just whole cell whether empty or one word no path
              ws.Cells(output_row, 2) = account 'print account ID to oputput
  
              data_col = data_col - 1 'domain second from end cell is now highlighted (since no domain in account cell)
              Do While data_col &gt; 0 'generate domain from rest of row
                  domain_bit = Cells(data_row, data_col).Value &amp; domain_bit 'domain built backwards
                  data_col = data_col - 1 'check next column for more of location name
              Loop
  
              ws.Cells(output_row, 1) = domain_bit 'output to file
          End If
  
      data_col = LastCol
      data_row = data_row + 1
      output_row = output_row + 1
      End If
  
  'Next increment
  ws.Range("E" &amp; 1) = unknown_count
  increment = increment + 1
  
  If increment = LastRow Then
      MsgBox (Str(increment) &amp; "=" &amp; Str(LastRow))
  End If
  
  Loop
  </code></pre>