![]() |
|
#2
|
|||
|
|||
|
Yes it can be done. Here is code that creates new sheets that conform to a TEMPLATE sheet located in the same workbook.
Code:
Sub MoreAndMoreSheets()
Dim ListSh As Worksheet, BaseSh As Worksheet
Dim NewSh As Worksheet
Dim ListOfNames As Range, LRow As Long, Cell As Range
With ThisWorkbook
Set ListSh = .Sheets("List") '--Qualify our sheets.
Set BaseSh = .Sheets("Template")
End With
LRow = ListSh.Cells(Rows.Count, "A").End(xlUp).Row '--Get last row of list.
Set ListOfNames = ListSh.Range("A2:A" & LRow) '--Qualify our list.
With Application
.ScreenUpdating = False '--Turn off flicker.
.Calculation = xlCalculationManual '--Turn off calculations.
End With
For Each Cell In ListOfNames '--For every name in list...
BaseSh.Copy After:=Sheets(Sheets.Count) '--Copy Template sheet.
Set NewSh = ActiveSheet '--Let's name it NewSh.
With NewSh
On Error GoTo messageinfo '--In case of errors.
.Name = Cell.Value '--Set the sheet's name to that of our current name in list.
GoTo LetUsContinue '--Skip to the LetUsContinue block.
LetUsContinue:
On Error GoTo 0 '--Turn off error handling.
.Range("C1") = Cell.Value '--Change C1 to the name of current sheet.
.Calculate '--Calculate page.
.Cells.Copy '--Change all cells...
.Cells.PasteSpecial xlPasteValues '--... to values.
End With
Next Cell
With Application
.Calculation = xlCalculationAutomatic '--Return to automatic calculation.
.ScreenUpdating = True '--Return to proper state.
End With
Exit Sub
messageinfo: '--In case of duplicate names...
MsgBox ("Duplicate name exists")
Err.Clear
On Error GoTo 0
End Sub
When you run the macro it auto creates all of the sheets in the list based on the TEMPLATE sheet. See attached. |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exporting data to an excel template | Stevie23 | Excel Programming | 3 | 04-05-2018 12:12 AM |
excel 2013 template
|
jassie | Excel | 1 | 03-06-2017 10:36 AM |
| Excel Invoice Template | DMU62 | Excel | 19 | 11-02-2016 12:17 PM |
Excel Default Template
|
kneghx | Excel | 1 | 05-13-2015 09:29 AM |
| Excel Chart Template | mdarcey | Excel | 0 | 01-26-2012 08:43 AM |