Loops for deleting rows

  • Thread starter Thread starter daniB
  • Start date Start date
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
 
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
 
Missed the "odd" in "all odd rows"

So don't use my suggestion.

--
Regards,
Tom Ogilvy

Tom Ogilvy said:
ActiveSheet.UsedRange.EntireRow.Delete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top