Creating N worksheets

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro can copy a spreadsheet in a workbook. I start of with two
spreadsheets in the workbook. The second sheet is the one I copy. On the
first worksheet I have the number of times the second spreadsheet is to be
copied in a cell, say C2. Below I have the name of each of the worksheets.
What I want to do is to copy the second worksheet N times where N is the
number in the cell C2 of the first worksheet - ie. I want to automatically
run my macro to copy a spreadsheet N times. I then want to run a macro for
renaming those worksheet according to names listed in the firsr worksheet.
How do I accomplish this?
 
This will do that:

Sub CopyNsheets()
Dim i As Long

For i = 1 To Worksheets("Sheet1").Range("C2").Value
Sheets("Sheet2").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = Worksheets("Sheet1").Range("C2").Offset(i, 0).Value
Next
End Sub

Mike F
 
Thank you.

Adrian

Mike Fogleman said:
This will do that:

Sub CopyNsheets()
Dim i As Long

For i = 1 To Worksheets("Sheet1").Range("C2").Value
Sheets("Sheet2").Copy After:=Worksheets(Sheets.Count)
ActiveSheet.Name = Worksheets("Sheet1").Range("C2").Offset(i, 0).Value
Next
End Sub

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top