Deleting every other row with VBA

  • Thread starter Thread starter Sarah
  • Start date Start date
S

Sarah

All,

Can anyone assist me with the VBA code that will allow me to delete
every other row (they are blank) beginning with 1 to a defined last
row?

Thanks!
Sarah
 
Hi Sarah

Try this one for the selection

Sub DeleteEveryOtherRow()
'Chip Pearson
Dim RowNdx As Long
For RowNdx = Selection.Cells(Selection.Cells.Count).Row _
To Selection(1, 1).Row Step -2
Rows(RowNdx).Delete
Next RowNdx
End Sub
 
Hi Sarah,

It wrks better if you start at the bottom and work up. Try modifying this
code for your use

Sub DeleteRows()
Range("A65536").End(xlUp).Offset(-1, 0).Select
Do Until ActiveCell.Row = 2
Selection.EntireRow.Delete
ActiveCell.Offset(-2, 0).Select
Loop
End Sub

HTH, Greg
 
This will work with either an even or odd number of rows (didn't try to
figure out which), but not both. Try changing =2 to <=2
 
Don't select, it is so wasteful

Sub DeleteRows()
Dim i As Long
i = Range("A" & Rows.Count).End(xlUp).Row
Do Until Cells(i,"A").Row = Activecell.Row
Cells(i-1,"A").EntireRow.Delete
i = i - 2
Loop
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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