Delete rows and filtering

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
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.

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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
And for the sort try removing the .row and change the & to , to make it
Code:
Range("F2",Range("F" & Rows.Count).End(xlUp)).Sort
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top