Create new Worksheet [and pasteAll, there-in]for each consecutive range of data copied

GERALDRAHMAN

New Member
Joined
Apr 11, 2013
Messages
38
Hi All


I would like a Macro that can copy values from 5 rows in a worksheet, starting from Row 1. Each "Batch" copied to a new worksheet should contain values from 5 rows, so first batch would be from Row 1 - Row 5 → copied to Sheet 1 , then Row 6 - Row 10 → copied to Sheet 2 , then Row 11 - Row 15 → copied to Sheet 3 ...... etc. This should be done until there are no values in the last row.


So, the workbook would start off with only one worksheet, which could be named "source" for convenience and end up with many more sheets depending on how many rows are in the source worksheet, which can vary from time to time. There are 3 other "contraints/conditions that need to be considered 1. the number of columns in the "source worksheet may vary from 5 columns up to 30 columns. 2. The formatting that was applied to the values in the "source" worksheet need to be maintained. 3. The data posted should start in cell A1 for each new sheet.


Thanks in advance


Gerald
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Copy this procedure to your standard code module. It will create new sheets after your existing sheets and name them. There will be five rows per sheet except the last sheet may only contain the number of rows remaining after dividing by five.
Code:
Sub batching()
Dim sh As Worksheet, lr As Long, i As Long
Set sh = Sheets("source")
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
     For i = 1 To lr Step 5
        Sheets.Add After:=Sheets(Sheets.Count)
        ActiveSheet.Name = "Batch " & i
        sh.Cells(i, 1).Resize(5, 1).EntireRow.Copy ActiveSheet.Range("A1")
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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