Quickly delete rows in a range containing certain value

bran

New Member
Joined
Jun 14, 2011
Messages
9
Hi, this is my first post so please let me know any mistakes.

I have a worksheet of 10,000 rows containing data seperated into multiple columns. I want to select all the cells in one column that don't contain a user input value and then delete all the rows containing those cells.

I can do this with a loop but it takes far too long. I'm really looking for any method that can quickly get rid of the unwanted rows that doesn't use loops.
 
Hi VoG,

Is it possible to use this code to delete a range of say less than £500?

I've got 10000 lines of data and I Want the macro to delete all instances less than £500 (Both debits and credits) Where would I put this on your code, or anyone?! I'm guessing I change the W to AG in my case as that's the column I want it to look at?
 
Upvote 0

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try with a copy of your sheet

Code:
Sub Del_x()
With Columns("AG")
    .AutoFilter field:=1, Criteria1:="<500", Criteria2:="<-500"
    .Resize(Rows.Count - 1).Offset(1).EntireRow.Delete
End With
ActiveSheet.AutoFilterMode = False
End Sub
 
Upvote 0
That seems to have deleted all of my minuses ABOVE 500 and kept all the ones below in the spreadsheet.

It's also not touched anything with a positive figure for some reason :confused:

My range goes between 22000 and -270,000 and I need to delete anything less than £500 and -£500, don't see how your formula hasn't worked Mr VoG :(
 
Last edited:
Upvote 0
I think a loop might be better

Code:
Sub Del_x()
Dim i As Long, LR As Long
LR = Range("AG" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
For i = LR To 2 Step -1
    If Abs(Range("AG" & i).Value) < 500 Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
YES!

Absolute legend!

Any suggestions on some sites or info I can look at to figure out what all that code actually means and how it's working? That's extremely helpful, I want to use that again and again elsewhere!

Kind Regards
Jonathan
 
Upvote 0
You sir, are a legend!

Thanks very much for all your help, very much appreciated and sorry for thread jacking whoever made it!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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