Pennyc, The code below will let you define which sheet is to be copied, and
which sheet has the number list on it and what cells contain that list. Edit
those values appropriately and just run the macro to make the copies.
Remember that your number list must contain unique numbers, no worksheet can
be renamed the same as one that already exists in a workbook. The code
guards against that type of error.
To put the code to work:
Open your workbook, press [Alt]+[F11] to open the VB Editor and use Insert
--> Module to create a code module. Copy the code below and paste it into
that module and then edit it for your workbook. Run it from Tools --> Macro
--> Macros
Sub MakeSheetCopies()
Const SheetToCopy = "SheetToCopy" ' name of sheet
Const ListSheetName = "SheetWithList" ' name of sheet
Const startOfList = "A2" ' first of list's address
Const endOfList = "A7" ' end of list's address
Dim copySheet As Worksheet
Dim numberList As Range
Dim anyNumber As Range
Set copySheet = ThisWorkbook.Worksheets(SheetToCopy)
Set numberList = ThisWorkbook.Worksheets(ListSheetName). _
Range(startOfList & ":" & endOfList)
For Each anyNumber In numberList
copySheet.Copy After:=Sheets(Worksheets.Count)
On Error Resume Next
'if sheet name already exists, will generate an
'error that we must deal with
ActiveSheet.Name = SheetToCopy & "-" & anyNumber
If Err <> 0 Then
Err.Clear
MsgBox "Could not rename " & ActiveSheet.Name
End If
On Error GoTo 0
Next
'good housekeeping
Set copySheet = Nothing
Set numberList = Nothing
End Sub
Pennyc said:
I need to generate multiple copies of one worksheet within a workbook and
automatically name each of those new worksheets (sequentially) based on a
list of numbers on another sheet in the same workbook. Does anyone know of a
way to do this?
Thanks!