Fastest way to delete 20k+ rows

Blunder1

Active Member
Joined
Jun 2, 2010
Messages
250
Hi All,

My sheet contains anyting from 20,000 to 40,000 rows of data. Withing this data i need to delete 95% of this based on cells values in columns M. The values in column M is comes from a look up, and anything with an #N/A value needs the entire row to be deleted. I've tried copying to another sheet, filters etc but anything i try can take ages to run. I have 7 worksheets in the workbook all the same size then have to run this through 60 workbooks, so i'm looking at over a days to run the code providing it doesn't crash my PC!

Does anyone have any suggestion how i can do this quicker?

Thanks in advance

Blunder
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Sort the table according to column M so that all of the #N/As are in a contiguous range.

Next highlight column M
F5
Special
Formulas > Errors
Ok

Then delete the rows (ctl+-) and choose rows when prompted.
 
Upvote 0
If you can sort the data on column M first, then you will only be deleting one block of cells and that should be faster. You could also use ClearContents instead of deleting the rows.
 
Upvote 0
You could try like this. It would help if you sorted by column M first.

Code:
Sub test()
Columns("M").SpecialCells(xlCellTypeFormulas, xlErrors).EntireRow.Delete
End Sub
 
Upvote 0
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
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