Create multiple files from template

ahmedmohamedkamal

New Member
Joined
Dec 28, 2019
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hi every one
I have a code edited from old thread that create new excel files based on template and named after specified range in the master sheet
i have a problem that it copy the first cell A1 in every C6 for all generated files
i need A1 copied to C6 1st file and A2 copied to C6 2nd file ...........etc also i need to make the range dynamic according to used cells no just from a1 to a8
The code is
VBA Code:
Public Sub SaveTemplate()
  Const strSavePath As String = "C:\My Documents\"
  Const strTemplatePath As String = "C:\My Documents\template.xls"


  Dim rngNames As Excel.Range
  Dim rng As Excel.Range
  Dim wkbTemplate As Excel.Workbook

  Set rngNames = ThisWorkbook.Worksheets("Sheet1").Range("A1:A8").Values

  Set wkbTemplate = Application.Workbooks.Open(strTemplatePath)

  For Each rng In rngNames.Cells
    wkbTemplate.Worksheets("Sheet1").Range("C6").Value = ThisWorkbook.Worksheets("Sheet1").Range("A1:A8").Value
    wkbTemplate.SaveAs strSavePath & rng.Value
  Next rng

  wkbTemplate.Close SaveChanges:=False
End Sub
 
Last edited by a moderator:
Ok, add this line
Rich (BB code):
    With wkbTemplate.Worksheets("Sheet1")
        .Range("C6").Value = rng.Value
        .Range("F15").Value = rng.Offset(3, 6).Value
        .Range("C14").Resize(rngC.Count).Value = rngC.Value
        .Range("L6").Value = thisworkbbok.Sheets("Sheet1").Range("H2").Value
    End With
Sorry but it didn't fo any thing
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Are you sure there are values in G4, G5 etc of the Master sheet? If so they should have been copied to F15 of the new file.
 
Upvote 0
Are you sure there are values in G4, G5 etc of the Master sheet? If so they should have been copied to F15 of the new file.
it worked thank you very much
i wanted f14 and the code was f15 which was hidden any way thanks alot
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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