Deleting rows loop

  • Thread starter Thread starter briskbaby
  • Start date Start date
B

briskbaby

Hi guys, I'm trying to create a loop that will delete the next row until
it hits a blank. Only problem is I do not know how to offset to the next
row and than select that entire row to delete. Thanks in advance.

Sub Macro2()

Sheets("test").Select
Sheets("test").Copy Before:=Sheets(1)
Rows("1:6").Select
Range("B6").Activate
Selection.Delete Shift:=xlUp
Cells.Select
With Selection
..Orientation = 0
..AddIndent = False
..ShrinkToFit = False
..MergeCells = False
End With
Rows("4:4").Select
Selection.Delete Shift:=xlUp
Do
Rows("5:5").Select
Selection.Delete Shift:=xlUp
Rows("6:6").Select
Selection.Delete Shift:=xlUp
Rows("7:7").Select
Selection.Delete Shift:=xlUp
Loop Until IsEmpty(ActiveCell.Offset(1, 0))
End Sub
 
lastrow = cells(rows.count,1).End(xlup).Row
for i = lastrow to ActiveCell.row Step -1
rows(i).Delete
Next
 
I apologize for my lack a clarity, what the macro does is delete a ro
and then proceeds to the row after and deletes that for example:

Row 3 <--- Stays
Row 4 <--- Deleted
Row 5 <--- Stays
Row 6 <--- Deleted
Row 7 <--- Stays
Row 8 <--- Deleted

I guess my example was misleading because when I shift up Row 5 (whic
stays) becomes Row 4.

Thank
 
lastrow = cells(rows.count,1).End(xlup).Row
for i = lastrow to ActiveCell.row Step -2
rows(i).Delete
Next

If that deletes the wrong rows, then change Lastrow to

lastrow = cells(rows.count,1).End(xlup).Row - 1
 

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