0
Thanks

A few words of thanks would be greatly appreciated.

Excel - A macro to delete alternate rows




Issue


I want to delete every alternate row from my work sheet. I tried recording macro, but it only deletes a particular row as shown below (Row 4:4). How can this macro be converted to a more versatile one?


Sub Macro3()   
 Macro3 Macro   
 Keyboard Shortcut: Ctrl+q   
 Rows("4:4").Select   
Selection.Delete Shift:=xlUp   
End Sub  

Solution


Just use the macro below:
Sub deleteAlternateRow()  
Dim startAtRow, endAtRow, rowCounter As Long  
startAtRow = 2  
endAtRow = 100  
For rowCounter = startAtRow To endAtRow  
    Rows(rowCounter).Select  
    Selection.Delete Shift:=xlUp  
Next  
End Sub 

Note that


Thanks to rizvisa1 for this tip on the forum.
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Excel - A macro to delete alternate rows », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

0 Comments