Is there a faster way to delete rows ?
I just need to delete rows with odd row numbers from row 3 to the last row with data in it
Below code works but is very slow:
Dim toDelete As Range
For icount = endRow To 3 Step -2
If toDelete Is Nothing Then
Set toDelete = Rows(icount)
Else
Set toDelete = Union(toDelete, Rows(icount))
End If
Next
toDelete.Delete shift:=xlUp
I already posted this solution, but it was in the context of a
Range(address)
throwing errors whenaddress
exceeded some length.But now the topic is strictly that of the fastest way to delete many rows and I'll assume it's required to stick to actually delete rows (i.e. mantaining formatting, formulas, formula references...)
So I'll post here that solution again (under the header of "Delete by Address" approach) along with a 2nd one ("Delete by Sort" approach) which is much much faster (1st takes some 20 secs, 2nd takes some 0,2 secs to process some 40k rows, i.e. delete 20k rows)
Both solutions are slightly specialized after the OP
For icount = endRow To 3 Step -2
thing, but it can be easily made more general"Delete by Address" approach
"Delete bySort" approach