title: Do While loop keeps terminating and setting values to 0
body: <p>I'm going crazy with this. I have a basic block of code in one of my excel vba modules that keeps terminating early and upon using break lines, i find that all my inner values are being reset to 0. </p>
  
  <p>My goal: </p>
  
  <ol>
  <li>check if (bottom_cell + once_cell_up) > (bottom_cell)</li>
  <li>if so, perform (bottom_cell).Value + (bottom_cell + one_cell_up).Value</li>
  <li>assign this result in (bottom_cell).Value</li>
  <li>if not, increase one_cell_up value by one and repeat process until 
         cell with larger value is found</li>
  </ol>
  
  <p>This is the basic jist. I have some safeguards in the block for if all values above the current value are less than it, once the for loop loops to the end, etc.</p>
  
  <p>After running my code, diff_value, upcol, and upcol_maxflag are all 0, mysteriously. p is 51. </p>
  
  <p>Code and variable definitions are below:</p>
  
  <p>upcol - up column counter; increases if above cell value isn't larger
  filled_col - string array of cell addresses
  filled_collen - length of filled_col array (it's a 1D array)
  upcol_maxflag - for use if, after going through all cells above the current<br>
                  index cell, none are larger and thus it'll break out of the
                  loop for the next index</p>
  
  <p>Excel VBA code (Excel 2013):</p>
  
  <pre><code>Dim p As Integer
  Dim diff_value As Double
  Dim upcol As Integer
  Dim upcol_maxflag As Integer
  For p = (filled_collen - 1) To 1
      diff_value = 1
      upcol = 1
      upcol_maxflag = 0
      Do While diff_value &gt; 0
          diff_value = Range(filled_col(p)).Value - _
                       Range(filled_col(p - upcol)).Value
          If Val((Range(filled_col(p)).Value) &gt; _
             Val(Range(filled_col(p - upcol)).Value)) Then
              upcol = upcol + 1
          End If
          If (upcol = p) And (p &lt;&gt; 1) Then
              upcol_maxflag = 1
              Exit Do
          End If
      Loop
      If (upcol_maxflag &lt;&gt; 1) Then
          Range(filled_col(p)).Value = Range(filled_col(p)).Value _
          + Range(filled_col(p - upcol)).Value
      End If
  Next
  </code></pre>
  
  <hr>
  
  <p>Thanks to anyone that can figure out what's going on here. I feel like I had a decent grasp on excel VBA but this is kicking my butt.</p>