VBA MACRO TO CUT AND PASTE ON LOOP

brunoricardo

New Member
Joined
Aug 1, 2013
Messages
20
Hi guys!

I'm wondering how to build a macro for the following repetitive tasks:

1. Selecting a specific cell,
2. Goes to the last row with data,
3. Selects all the row, since the 3rd column until the end,
4. Cut all these cells
5. Pasts on the column A of the first blank row below the previous line,
6. It must repeat until finish all the columns with data.

To better explain, I letf here a video with a sample video on link below:




Tanks a lot!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Select the starting cell with data in columns, then run this
VBA Code:
Sub Test()

Application.ScreenUpdating = False
Restart:
Set Rng = Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(0, 2).End(xlToRight))
Rng.Copy ActiveCell.Offset(1)
Rng.Clear
ActiveCell.Offset(1).Select
If Not Len(ActiveCell.Offset(0, 2)) = 0 Then GoTo Restart

End Sub
 
Upvote 0
Hi Brunoricardo,

Please use below code:

VBA Code:
Sub arrangeData()
Dim lastRow As Integer, lastCol As Integer

lastRow = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
'MsgBox lastRow
Do While Sheets("Sheet1").Cells(lastRow, 3) <> ""
    lastCol = Sheets("Sheet1").Cells(lastRow, Columns.Count).End(xlToLeft).Column
    
    'MsgBox lastCol
    Sheets("Sheet1").Range("C" & lastRow).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Cut Sheets("Sheet1").Range("A" & lastRow + 1)
    lastRow = lastRow + 1
Loop
End Sub
 
Upvote 0
Hi Brunoricardo,

Please use below code:

VBA Code:
Sub arrangeData()
Dim lastRow As Integer, lastCol As Integer

lastRow = Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Row
'MsgBox lastRow
Do While Sheets("Sheet1").Cells(lastRow, 3) <> ""
    lastCol = Sheets("Sheet1").Cells(lastRow, Columns.Count).End(xlToLeft).Column
   
    'MsgBox lastCol
    Sheets("Sheet1").Range("C" & lastRow).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Cut Sheets("Sheet1").Range("A" & lastRow + 1)
    lastRow = lastRow + 1
Loop
End Sub
Thanks a lot! It works perfectly ??
 
Upvote 0

Forum statistics

Threads
1,224,871
Messages
6,181,497
Members
453,047
Latest member
charlie_odd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top