Sub Delete_Data()
Set stInp = Sheets("Sheet2")
oriInputCnt = stInp.Cells(stInp.Rows.Count, "H").End(xlUp).Row
If oriInputCnt > 5 Then stInp.Rows("6:" & oriInputCnt).EntireRow.Delete Shift:=xlUp
End Sub
Sub Deletes()
Dim Ws As Worksheet
Dim LR As Long, i As Long
Set Ws = Worksheets("Sheet2")
LR = Ws.Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 6 Step -1
With Ws.Cells(i, "H")
If .Value <> "M" Then
.EntireRow.Delete
End If
End With
Next i
End Sub
Please try below:
Open in new window