Loops for deleting rows

D

daniB

I need to go through a spreadsheet and delete all odd rows.....I have
sooooo many rows that it takes forever and crashes....I need some VBA
which doesnt crash my spreadsheet!!!

Any ideas??

Thanks Dani
 
C

Chip Pearson

Dani,

Try something like the following:

Dim LastRow As Long
Dim RowNdx As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp)
If LastRow Mod 2 = 0 Then
LastRow = LastRow + 1
End If
For RowNdx = LastRow To 1 Step -2
Rows(RowNdx).Delete
Next RowNdx
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Top