ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating N worksheets (https://www.excelbanter.com/excel-programming/373611-creating-n-worksheets.html)

Adrian Watts

Creating N worksheets
 
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?

Mike Fogleman

Creating N worksheets
 
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
"Adrian Watts" <Adrian wrote in message
...
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?




Adrian Watts[_2_]

Creating N worksheets
 
Thank you.

Adrian

"Mike Fogleman" wrote:

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
"Adrian Watts" <Adrian wrote in message
...
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?






All times are GMT +1. The time now is 07:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com