VBA to delete all rows except

frets

New Member
Joined
Oct 21, 2008
Messages
24
Hi,

My problem is, I need code to delete all rows of data that doesn't meet the following criteria:

WPU0576
WPU0577
WPU0578....etc.

It needs to search through column A and also i have over 600K lines of data.

Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
frets,

WPU0576
WPU0577
WPU0578....etc.

1. Does the column contain a title? If so, what row?

2. What is the range of columns in your dataset?

3. Please explain in more detail WPU0578....etc.


So that we can get it right the first time, can we see a sample of your worksheet?

You can upload a sample of your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
try this

Sub sumbyemp2()
Dim i As Long
Dim LR As Long
Application.ScreenUpdating = False
Sheets("sheet1").Select
LR = Cells(Rows.Count, 1).End(xlUp).Row
For i = LR To 2 Step -1
If Range("a" & i) <> "WPU0576" And Range("a" & i) <> "WPU0577" And Range("a" & i) <> "WPU0578" Then
Range("a" & i).EntireRow.Delete Shift:=xlUp
End If
Next i
Application.ScreenUpdating = True

End Sub



If you need to add more criteria just add them to this line

If Range("a" & i) <> "WPU0576" And Range("a" & i) <> "WPU0577" And Range("a" & i) <> "WPU0578" and condition4 and condition 5 Then

add conditions with this code

And Range("a" & i) <> "add value here"
And Range("a" & i) <> "add value here"

etc

Tested and it works
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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