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
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