Excel Swap Rows (Multiple Rows)

April 21, 2011 at 09:38:00
Specs: Windows XP
I would like to figure out how to swap multiple rows. I need to start with swapping rows 19 and 20. Then 39 and 40. Then 59 and 60, and so forth. So starting with 19 and 20 and the next rows 20 rows down respectively.

Ive tried recording a macro but is there anyway to get it to keep going and knowing to do it every 20 so I dont have to manually enter the numbers in the macro. It would take forever.


Sub Swap Rows()
'
' Swap Rows Macro
'

'
Rows("20:20").Select
Selection.Cut
Rows("19:19").Select
Selection.Insert Shift:=xlDown
Rows("40:40").Select
Selection.Cut
Rows("39:39").Select
Selection.Insert Shift:=xlDown
Rows("60:60").Select
Selection.Cut
Rows("59:59").Select
Selection.Insert Shift:=xlDown
End Sub


See More: Excel Swap Rows (Multiple Rows)

Report •


#1
April 21, 2011 at 16:11:05
How about this...

 Sub SwapRows()
   For rw = 20 To 60 Step 20
     Rows(rw).Cut
     Rows(rw - 1).Insert shift:=xlDown
   Next
 End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •
Related Solutions


Ask Question