View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Delete every other line in LARGE worksheet

You could use a helper column with
=ISEVEN(ROW())
and copy down. Then copy/paste special the values to hardcode the
TRUE/FALSE values, sort the list (using this new column) and delete the rows
you need. But I have sometimes had problems w/deleting large ranges,
sometimes even having the computer lock up on me.

This macro took about 3 minutes to delete rows 1 through 45001 (every other
row - change as needed). I set it to delete about 2000 rows at a time as it
seems VBA started slowing down as the range to delete gets bigger. It seemed
to me faster than deleting one large range at the end and deleting one row at
a time. You can, of course change it as you see fit.


Sub Delete()
Dim i As Long
Dim rngDelete As Range

Application.ScreenUpdating = False

With Sheet1
For i = 45001 To 1 Step -2
If rngDelete Is Nothing Then
Set rngDelete = .Cells(i, 1)
Else
Set rngDelete = Union(rngDelete, _
.Cells(i, 1))
End If
Application.StatusBar = i
If rngDelete.Cells.Count Mod 2000 = 0 Then
rngDelete.EntireRow.Delete
Set rngDelete = Nothing
End If
Next i
End With

If Not rngDelete Is Nothing Then _
rngDelete.EntireRow.Delete

Application.ScreenUpdating = True
Application.StatusBar = False
End Sub


" wrote:

Can anyone think of a FAST way to delete every other line in a 45,000
line worksheet?

I can do a loop with Range("A"&Loop).EntireRow.Delete, but it takes
almost 10 minutes.

I was thinking of somehow selecting every other line and doing one HUGE
delete, but not sure if Excel could handle that or if it would be any
faster.

Any ideas?!!

Thanks.