title: How to loop on range of rows in LibreOffice Calc spreadsheet, comparing cell values, setting cell values and deleting row, if condition is true
body: <p>I have the following requirement in my <strong>LibreOffice Calc</strong> spreadsheet:</p>
  
  <hr>
  
  <p>ForEach Row 'r' in selected range, 
  starting from the last row in the range, 
  and moving backwards (up) one row at a time,</p>
  
  <p>do some cell value comparisons, and based on that, either skip the row, 
  or set some cell values, and delete the selected row,
  then proceed with the same process, with the row just above that.</p>
  
  <hr>
  
  <p><strong>ie.,</strong> </p>
  
  <p>Representing <code>CellValue(Column[A], Row[r])</code>
  as <code>A[r]</code>,</p>
  
  <p>And Representing the row before (just above) that,
  as <code>A[r-1]</code>,</p>
  
  <p>I need to do the following:</p>
  
  <pre><code>  FOR (r = LastRowInSelectedRange; r&gt;1; r=r-1) {
  
      IF FollowingConditionsAreTrue (
        (r &gt; 1)
        AND (A[r] IsEqualTo A[r-1])
        AND (B[r] IsEqualTo C[r-1])
        AND (E[r] IsEqualTo E[r-1])
      ) ThenDoTheFollowing {
  
        SET C[r-1] = C[r]
        DeleteRow(r)
  
      } EndIF
  
    } EndFOR
  </code></pre>
  
  <hr>
  
  <p><strong>Question:</strong>
  How can we implement this in <strong>LibreOffice Calc</strong>?</p>