PDA

View Full Version : CREATE WORKBOOKS FROM TEMPLATE WORKSHEET AND TABLE OF DATA



JILBO
05-21-2021, 02:41 AM
Hi,
Hopefully can explain this well enough, I've attached a workbook with 2 Worksheets , CTR Data & CTR Out

I'm after some code that can create a new workbook from the CTR Out Template once its been populated in sequence with the values from the table in the CTR Data Sheet. The Name of the file is the 'Number' (which I also required within cell c5 on the CTR out.

The CTR Data table {CTR_Data} could be anything from 1 to 50 rows long.

Thanks In Advance

p45cal
05-21-2021, 05:34 AM
Sub blah()
With Sheets("CTR Out")
For Each rw In Range("CTR_DATA").ListObject.DataBodyRange.Rows
.Range("C5,C11,C14:C17").ClearContents
.Range("C5").Value = rw.Cells(1).Value
.Range("C11").Value = rw.Cells(2).Value
.Range("C14").Value = rw.Cells(3).Value
.Range("C15").Value = rw.Cells(4).Value
.Range("C16").Value = rw.Cells(5).Value
.Range("C17").Value = rw.Cells(6).Value
.Copy
ActiveWorkbook.Close True, "C:\Users\Public\Documents\" & rw.Cells(1).Value '<<< adjust the path for your system
Next rw
.Range("C5,C11,C14:C17").ClearContents
End With
End Sub

JILBO
05-21-2021, 05:59 AM
Off to try this straight away!!!!

Thank you so much for this!

JILBO
05-21-2021, 06:03 AM
Brilliant ! I've been trying to figure this out and searched the web high and low all week. I owe you a beer or two or more!