Hello, i've searched google and Mr Excel.....but just cant quite get there.
I have a master list with alot of data.
I am looking for a macro to run to create a new worksheet for each row, copying a template to create the new worksheet.
The new worksheet name would be copied from A3:A400
I've managed to create a macro to do this.
However i then want to use some data from the Master List to populate cells within the new worksheets as they are created.
Master List B3 to populate New Worksheet D1
Master List F3 to populate New Worksheet D2
Master List G3 to populate New Worksheet D3
Master List H3 to populate New Worksheet D4
....of course as new worksheets are created it will move down a row on the Master List to copy over.
So found this code, which creates the new worksheets as expected....but cannot figure out the copying data into the cell.
Thanks.
I have a master list with alot of data.
I am looking for a macro to run to create a new worksheet for each row, copying a template to create the new worksheet.
The new worksheet name would be copied from A3:A400
I've managed to create a macro to do this.
However i then want to use some data from the Master List to populate cells within the new worksheets as they are created.
Master List B3 to populate New Worksheet D1
Master List F3 to populate New Worksheet D2
Master List G3 to populate New Worksheet D3
Master List H3 to populate New Worksheet D4
....of course as new worksheets are created it will move down a row on the Master List to copy over.
So found this code, which creates the new worksheets as expected....but cannot figure out the copying data into the cell.
Thanks.
VBA Code:
Sub SheetsFromTemplate()
Dim wsMaster As Worksheet, wsTemp As Worksheet, wasVisible As Boolean
Dim shNames As Range, Nm As Range, wsEntry As Worksheet, entryName
With ThisWorkbook
Set wsTemp = .Sheets("Template")
wasVisible = (wsTemp.Visible = xlSheetVisible)
If Not wasVisible Then wsTemp.Visible = xlSheetVisible
Set wsMaster = .Sheets("House List")
Set shNames = wsMaster.Range("A3:A" & Rows.Count).SpecialCells(xlConstants)
Application.ScreenUpdating = False
For Each Nm In shNames
entryName = Nm.Text
Set wsEntry = Nothing 'EDIT
On Error Resume Next 'ignore error if no sheet with this name
Set wsEntry = .Sheets(entryName)
On Error GoTo 0 'stop ignoring errors
If wsEntry Is Nothing Then
wsTemp.Copy after:=.Sheets(.Sheets.Count)
Set wsEntry = .Sheets(.Sheets.Count) 'get the copy
wsEntry.Name = CStr(Nm.Text)
End If
With wsEntry
'transfer/update values from Master sheet
.Range("D1").Value = entryOutlet
'...etc
wsMaster.Hyperlinks.Add Anchor:=Nm, Address:="", _
SubAddress:=wsEntry.Range("B3").Address(, , , True), _
TextToDisplay:=Nm.Text
End With
Next Nm
wsMaster.Activate
If Not wasVisible Then wsTemp.Visible = xlSheetHidden
Application.ScreenUpdating = True
End With
MsgBox "Woo hoo, done"
End Sub