Repeat cutting and pasting to the row below

Closed
Amit - 11 Mar 2010 à 12:39
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 11 Mar 2010 à 14:05
Hello,
I am trying to create a macro loop that cut every row at the D column and paste it to the next row starting at the A column, until there is no more data on the D column. The following is the backbone of my macro, they are not functional, the underlined ones are what I would like to be replaced by actual correct coding.

Sub Cut_Paste()

Dim n as Integer

Loop n = 1, infinity

Range("D .n").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Cut
Range("A .(n+2)").Select
ActiveSheet.Paste

Loop Until if D .(n+2) == empty cell

End Sub
Related:

1 response

rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 766
11 Mar 2010 à 14:05
If you want to just copy whole D to A and just move it one cell down, why this loop. I am sure I am missing some thing here

Any how, this will give you last used cell in D column
lastRowD = Cells(ActiveSheet.Rows.Count, "D").End(xlUp).Row