[Q] How to create new worksheets based on an array (via named range)

January 10th, 2012 - 02:18 pm ET by John | Report spam
How could I use a named range to create a series of new worksheets?

Details:
I have a named range (A1:A3) called NewSheetNames. I want to create a
new worksheet for each value in the named range. (3 sheets in this
example).

Example:

NewSheetNames (named range)
A1: Sheet1
A2: AnotherSheet
A3: NewSheet

Click button, and vba creates three new sheets called:
1. Sheet1
2. AnotherSheet
3. NewSheet

Any pointers are greatly appreciated!
email Follow the discussionReplies 4 repliesReplies Make a reply

Replies

#1 John
January 10th, 2012 - 02:28 pm ET | Report spam
On Jan 10, 11:18 am, John wrote:
How could I use a named range to create a series of new worksheets?

Details:
I have a named range (A1:A3) called NewSheetNames. I want to create a
new worksheet for each value in the named range. (3 sheets in this
example).



I found some code that got me started. Think this should work, but if
there's a better way I'm all ears!



Sub Create_Worksheets()

Dim rngMemberList As Range
Dim myCell As Range
Dim strSheetName As String

Set rngMemberList = Range("vbSheetExpandMemberList")

Application.ScreenUpdating = False
Application.EnableEvents = False

For Each myCell In rngMemberList
strSheetName = myCell.Value
'copy the template worksheet and then give it the name contained
in the sheetName variable.
Sheets("wsToCopy").Copy 'Before:=Sheets("Sum End")
Sheets("wsToCopy (2)").Name = sheetName
Next myCell

Application.ScreenUpdating = True
Application.EnableEvents = True

End Sub







Example:

NewSheetNames (named range)
A1: Sheet1
A2: AnotherSheet
A3: NewSheet

Click button, and vba creates three new sheets called:
1. Sheet1
2. AnotherSheet
3. NewSheet

Any pointers are greatly appreciated!

Similar topics