PDA

View Full Version : VBA copy template worksheet to multiple new worksheets based on a range



NFS79
01-12-2013, 07:21 AM
so, I'm new to all of this, I'm slowly trying to figure things out, bear with me if i dont use the correct terms... I appreicate any help anyone could provide

I'm looking for some help. I need to create multiple copies of a worksheet that i am using as a template (Employee Template) to a new worksheet in the same workbook and rename them based on a range of variables I have in another worksheet (worksheet"Manifold Team Metrics" Range "B4:B30")

maybe this is mroe clear, I need to make multiple copies of "Employee Template" worksheet and rename the copy to "bob" or "john" or whatever the names are in b4:b30

I'm guessing this can be done fairly easily... I just cant seem to figure it out. anyone got any ideas?

Thanks!

NFS79
01-12-2013, 09:41 AM
okay so I've got it adding the correct number of sheets, but i cant get it to rename based on the variables in my "Team Metrics" sheet...

this is what I have, anyone know how to rename as it copies?

'adds all employee sheets back
'
Dim cell As Range
Dim wks As Worksheet
On Error Resume Next
With ThisWorkbook.Worksheets("Manifold Team Metrics")
For Each cell In Sheets("Manifold Team Metrics").Range("B4:B30")
.Parent.Worksheets("Employee Template").Copy After:=.Parent.Worksheets(.Parent.Worksheets.Count)
Set wks = ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
wks.Name = .Cells(cell, "B4:B30").Value2
Next
End With
End Sub

NFS79
01-12-2013, 10:13 AM
okay, i think I got it. the first 3 cells in my column B were empty... so i just typed in some random text to fool it, here's what I got, now at the end of the code I'll just tell it to delete the first 3 sheets it added.... does anyone know how to just have it start at "B4" instead?

adds all employee sheets back
'
Dim i As Long
Dim wks As Worksheet
With ThisWorkbook.Worksheets("Manifold Team Metrics")
For i = 1 To .Cells(Rows.Count, "B").End(xlUp).Row
.Parent.Worksheets("Employee Template").Copy After:=.Parent.Worksheets(.Parent.Worksheets.Count)
Set wks = ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
wks.Name = .Cells(i, "B").Value2
Next
End With
End Sub