VBA to Copy Specific Cells into all Worksheets

Melissa2019

New Member
Joined
Jun 25, 2019
Messages
1
Hi.....I have a macro to create a new template workbook based upon the number of rows in my data tab. The macro also re-names each workbook with the name in column D of the data tab. Now I need to populate certain cells within the newly created workbooks. I'm not sure how to write the code so that it moves down one row each time data is copied into a new workbook. Below is what I have so far and it copies from row 2 into each worksheet I create. I would like to copy from row 2 into the first worksheet and then from row 3 into the next worksheet and so on. Any help is greatly appreciated.

Sub NewSheets()
Dim i As Integer
Dim ws As Worksheet
Dim sh As Worksheet
Set ws = Sheets("Template")
Set sh = Sheets("Data")
Application.ScreenUpdating = 0


For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
Sheets("Template").Copy After:=sh
ActiveSheet.Name = sh.Range("D" & i).Value
Sheets("Data").Select
Range("X2").Select
Selection.Copy
Sheets("Template").Select
Range("E3:I5").Select
ActiveSheet.Paste
Sheets("Data").Select
Range("Y2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Template").Select
Range("J3:L5").Select
ActiveSheet.Paste
Sheets("Data").Select
Range("Z2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Template").Select
Range("M3:Q5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Style = "Comma"
Sheets("Data").Select
Range("AA2").Select
Selection.Copy
Sheets("Template").Select
Range("R3:W5").Select
ActiveSheet.Paste
Next i
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try this

Code:
Sub NewSheets()
    Dim sT As Worksheet, sD As Worksheet, i As Integer, sN As Worksheet
    
    Application.ScreenUpdating = 0
    Set sT = Sheets("Template")
    Set sD = Sheets("Data")
    For i = 2 To sD.Range("D" & Rows.Count).End(xlUp).Row
        sT.Copy After:=sD
        Set sN = ActiveSheet
        sN.Name = sD.Range("D" & i).Value
        sD.Range("X" & i).Copy sN.Range("E3:I5")
        sD.Range("Y" & i).Copy sN.Range("J3:L5")
        sD.Range("Z" & i).Copy sN.Range("M3:Q5")
        sD.Range("AA" & i).Copy sN.Range("R3:W5")
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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