magemaester
New Member
- Joined
- Dec 17, 2017
- Messages
- 10
Hi guys,
I want to duplicate a worksheet 10 times, and rename those 10 sheets according to a table of names residing in another spreadsheet. Currently I've written the following code:
Dim iSheetNumber As Long
Dim rNewSheetNames As Range
Dim rName As Range
Set rNewSheetNames = Sheets("SheetNameTable").Range("E7:E16")
For iSheetNumber = 1 To 10
ActiveSheet.Copy After:=Sheets(Sheets.Count)
For Each rName In rNewSheetNames
ActiveSheet.Name = rName.Value
Next rName
Next iSheetNumber
I believe the error in this macro is that I've used nested For-Next statements, so the macro gets stuck inside the inner For Each-Next loop and doesn't really duplicate the sheets. Instead it just keeps trying to rename the same sheet over and over again. I'm a beginner VBA user and I couldn't figure out how to work around it. Can anyone help?
Thanks once again!
I want to duplicate a worksheet 10 times, and rename those 10 sheets according to a table of names residing in another spreadsheet. Currently I've written the following code:
Dim iSheetNumber As Long
Dim rNewSheetNames As Range
Dim rName As Range
Set rNewSheetNames = Sheets("SheetNameTable").Range("E7:E16")
For iSheetNumber = 1 To 10
ActiveSheet.Copy After:=Sheets(Sheets.Count)
For Each rName In rNewSheetNames
ActiveSheet.Name = rName.Value
Next rName
Next iSheetNumber
I believe the error in this macro is that I've used nested For-Next statements, so the macro gets stuck inside the inner For Each-Next loop and doesn't really duplicate the sheets. Instead it just keeps trying to rename the same sheet over and over again. I'm a beginner VBA user and I couldn't figure out how to work around it. Can anyone help?
Thanks once again!