Hi everyone
I want to delete rows with criteria and to keep the first header row, however the macro below has removed my header row. Also I would like to sort the column F in ascending order but it doesn't work:
Please could anyone point out my mistakes. Thanks.
I want to delete rows with criteria and to keep the first header row, however the macro below has removed my header row. Also I would like to sort the column F in ascending order but it doesn't work:
Please could anyone point out my mistakes. Thanks.
Code:
Private Sub deleteInactiveProjectRows()
Sheets("flattened").Select
Dim x As Long, LastRow As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For x = LastRow To 1 Step -1
If Cells(x, 6).Value <> "P-DD804" And Cells(x, 6).Value <> "P-E119" And Cells(x, 6).Value <> "P-E229" And _
Cells(x, 6).Value <> "P-EE830" And Cells(x, 6).Value <> "P-K220" And Cells(x, 6).Value <> "P-S397" And _
Cells(x, 6).Value <> "P-T271" Then
Rows(x).Delete
End If
Next x
' Range("F2" & Range("F" & Rows.Count).End(xlUp).Row).Sort _
' Key1:=Range("F2"), Order1:=xlAscending
Worksheets("flattened").Columns("A:L").AutoFit
End Sub