Bulk Row Deletion - Fastest method
quartz wrote ...
I have tried several different methods of deleting a lot of rows quickly.
I use test data in a single Excel sheet containing 54,102 rows by 22
columns. This data contained 24,266 rows targeted for deletion
The fastest method I have found in benchmarking tests is to... use
a "For...Each" loop to mark the rows for deletion in the sheet <snip
This ran fastest (6.5 minutes - which still seems like a long time when you
have to do it repeatedly). Does anyone know of a faster method?
Try this approach:
- copy the sheet to a new blank workbook;
- save and close this temp workbook;
- use a SQL query on the closed temp workbook to create an in-memory
ADO recordset of the data you want to *keep* (if you don't specify an
ORDER BY clause then the existing sort order will be retained);
- delete all the data in the original sheet;
- use CopyFromRecordset to populate the original sheet using the
retained data.
This should easily run in under 6.5 seconds... I'm sorry, did you say
*minutes*?!
Jamie.
--
|