select alternate rows - quickly

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a worksheet where I want to delete alternate rows. i.e. rows
1,3,5,7,9.......... because they contain no data. Currently I am holding the
control key and selecting every other row, then using the delete row toolbar
button. However I have many worksheets to do.
I thought I'd create a macro to automatically hilight alternate rows and
then just use the delete row button. I did create that macro but when using
it, instead of hilighting the alternate rows from where my cursor is inserted
it just hilights the same rows as when the macro was created (i.e. the wrong
rows).
How can I set something up that allows me to hilight alternate rows from
where I place my cursor.
 
Hi
try the following macro:
Sub delete_rows()
Dim lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For row_index = lastrow To 1 Step -1
If row_index mod 2 =1 then
Rows(row_index).delete
End If
Next
Application.ScreenUpdating = True
End Sub
 
This appears to delete all the rows and not just the alternate ones as desired?
 
Try this instead:

Code
-------------------

Sub delete_rows()
Dim lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For row_index = lastrow To 1 Step -1
If IsEven(row_index) = False Then
Rows(row_index).delete
End If
Next
Application.ScreenUpdating = True
End Sub

-------------------



Then add this code to the module


Code
 
RC,
Works fine here.
Unless you have some data 1 line below the range you think you are
processing.

Nick
 
select a column where the only cells that are blank are in the rows you want
to delete.

Do
Edit=>Goto => Special and select Blank Cells. Then do Edit=>Delete and
select entire row.

This assumes the cells are actually blank and don't just appear blank
because they contain a formula returning an empty string or contain spaces.
 
I'd love to know what is stopping you from sorting this?

Regards
Robert McCurdy

"If you can't, use Word"
 

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