Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
For r = LR To 3 Step -1
  IID = Cells(r, "A")
  Type1 = Cells(r, "C")
  If IID = Cells(r - 1, 1) And Cells(r, "C") = "D" Then
    Rows(r - 1).Delete
  ElseIf IID = Cells(r - 1, 1) And Cells(r, "C") <> "N" Then
    Rows(r).Delete
  End If
Next
End Sub