How do I loop through cutting n number of rows in a column to new columns?

DTime

New Member
Joined
Sep 22, 2017
Messages
8
Hello, I'm new to vba programming and I'm stuck...

How would I take a list of numbers in column A, and for every 5 rows cut and paste them to the top of the next available column until the list in the first column is empty?

Any help or examples would be greatly appreciated. I think i need a loop in a loop?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi. This wont be particularly quick but is hopefully easier to understand:

Code:
Set sh = Sheets("Sheet3") 'change sheetname to suit
Numrows = 5 'increment this number of rows
lr = sh.Range("A" & Rows.Count).End(xlUp).Row 'last row of data in column A
lr = WorksheetFunction.Ceiling(lr, Numrows) 'round up last row to nearest Numrows
a = 2 'paste into column 2 (B) to start

For i = Numrows To lr Step Numrows
    sh.Range(sh.Cells(i - Numrows + 1, 1), sh.Cells(i, 1)).Cut sh.Cells(1, a)
    a = a + 1
Next
 
Upvote 0
Thank you, so much! But question, why is it necessary to Set the tab in excel? when I didn't it gave me an error 424. Could you reference a selected cell for example to start?

You mentioned it not being particularly quick? How could it be made faster? is there a better method of approach? Maybe look for certain criteria and then paste them? idk
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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