Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default [Q] How to create new worksheets based on an array (via named range)

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default How to create new worksheets based on an array (via named range)

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 'Befo=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!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,522
Default How to create new worksheets based on an array (via named range)

Sub makeshtsfromrngSAS()
Dim c As Range
For Each c In Range("myrng")
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = c
Next c
End Sub
=====
On Jan 10, 1:28*pm, John wrote:
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 'Befo=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!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default [Q] How to create new worksheets based on an array (via named range)

Sub Add_Sheets()
Dim rCell As Range
For Each rCell In Range("A1:A3")
With Worksheets.Add(after:=Worksheets(Worksheets.Count) )
.Name = rCell.Value
End With
Next rCell
End Sub


Gord

On Tue, 10 Jan 2012 11:18:56 -0800 (PST), 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).

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!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 621
Default [Q] How to create new worksheets based on an array (via named range)

Better yet..........a variable range of names in Column A

Sub Add_Sheets22()
Dim rCell As Range
Dim rng As Range
Set rng = Range(Cells(1), Cells(Rows.Count, 1).End(xlUp))
For Each rCell In rng
With Worksheets.Add(after:=Worksheets(Worksheets.Count) )
.Name = rCell.Value
End With
Next rCell
End Sub


Gord

On Tue, 10 Jan 2012 14:44:37 -0800, Gord Dibben
wrote:

Sub Add_Sheets()
Dim rCell As Range
For Each rCell In Range("A1:A3")
With Worksheets.Add(after:=Worksheets(Worksheets.Count) )
.Name = rCell.Value
End With
Next rCell
End Sub


Gord

On Tue, 10 Jan 2012 11:18:56 -0800 (PST), 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).

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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
make a named range with an array not using a workseet cell range John S.[_5_] Excel Programming 1 November 12th 10 10:41 PM
Create Named Worksheets Airfive Excel Discussion (Misc queries) 5 September 27th 07 02:40 AM
inserting a named range into new cells based on a named cell Peter S. Excel Discussion (Misc queries) 1 June 4th 06 03:53 AM
Can you create dynamic named ranges containing array formulas? Marie J-son[_7_] Excel Programming 1 February 28th 06 01:02 PM
Q: Best way to take data from VBA into graphs without writing data to worksheets? (Can a named range refer to an array in memory only?) KR Excel Programming 2 December 16th 04 11:12 PM


All times are GMT +1. The time now is 10:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"