title: Compare Cell with Cell above VBA Excel
body: <p>I am new here.</p>
  
  <p>I am trying to build a quick VBA program to "flatten" a Bill of Materials by heirarchy (BOM Level) and Status.</p>
  
  <p>Here is some sample data:
  <a href="https://i.stack.imgur.com/OSFfu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OSFfu.png" alt="Sample BOM Data"></a></p>
  
  <p>The sample data shows a BOM with a Car as a top level assembly, Wheel and Engine as second level assemblies, and various children parts that make up those assemblies on the third and fourth level of the BOM.</p>
  
  <p>I want to delete any rows that have the value "<code>ZE</code>", "<code>ZM</code>", or blank in column <code>C</code>.</p>
  
  <p>I also want to delete any rows that have the value "ZA" and are also direct children of another "<code>ZA</code>" item. (Example - Delete the Rim row from the BOM because the Wheel is the Parent "<code>ZA</code>" item)</p>
  
  <p>Here is what I have so far:</p>
  
  <pre class="lang-vba prettyprint-override"><code>Sub deletechildren()
  
   Dim lr As Long, i As Long, k As Long
  
      lr = Cells(Rows.Count, 1).End(xlUp).Row
  
      For i = lr To 1 Step -1
          If i &gt; 2 Then
              k = i - 1
          End If
          If Cells(i, 3).Value = "ZA" And Cells(i, 1).Value = Cells(k, 1).Value Then
              Cells(i, 3).EntireRow.Delete
          ElseIf Cells(i, 3).Value = "ZE" Then
              Cells(i, 3).EntireRow.Delete
          ElseIf Cells(i, 3).Value = "ZM" Then
              Cells(i, 3).EntireRow.Delete
          ElseIf Cells(i, 3).Value = "" Then
              Cells(i, 3).EntireRow.Delete
          End If
      Next i
  
      lr = Cells(Rows.Count, 1).End(xlUp).Row
  
  End Sub
  </code></pre>
  
  <p>I am getting some error on the first part of the If statement, where I want to parse out any "<code>ZA</code>" status children from the "<code>ZA</code>" parent.</p>
  
  <p>Any ideas?  </p>