Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default copy all named ranges in a sheet to seperate sheets

I have a sheet that has lots of named ranges. What I need to do is take
each named range and copy it to a new sheet then name the sheet using
the named range. What I dont know how to do is loop through all the
named ranges.

I can do this and it works...

Sub Copy_Range()

ActiveSheet.Range("CPG0162").Select
Selection.Copy
Sheets("Sheet7").Select
Range("A1").Select
ActiveSheet.Paste
End Sub

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy all named ranges in a sheet to seperate sheets

Try something like:

Sub copythem()
Dim nm As Name
Dim tSht As Worksheet
Dim nSht As Worksheet
Set tSht = Sheets("Sheet1") '<< the sheet with the names
For Each nm In ThisWorkbook.Names
If nm.RefersToRange.Parent.Name = tSht.Name Then
Set nSht = Sheets.Add
Range(nm).Copy nSht.Cells(1)
On Error Resume Next
nSht.Name = nm.Name
On Error GoTo 0
Set nSht = Nothing
End If
Next nm
End Sub


Hope this helps
Rowan

Chris Salcedo wrote:
I have a sheet that has lots of named ranges. What I need to do is take
each named range and copy it to a new sheet then name the sheet using
the named range. What I dont know how to do is loop through all the
named ranges.

I can do this and it works...

Sub Copy_Range()

ActiveSheet.Range("CPG0162").Select
Selection.Copy
Sheets("Sheet7").Select
Range("A1").Select
ActiveSheet.Paste
End Sub

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default copy all named ranges in a sheet to seperate sheets

adapted from tom olgivy

Dim total As Double
Sub testbsrange()
Dim oname As Object
Dim rng As Range
total = 0
For Each oname In Worksheets("Sheet1").Parent.Names
Set rng = Nothing
On Error Resume Next
Set rng = oname.RefersToRange
On Error GoTo 0
If Not rng Is Nothing Then
total = total + Application.Sum(Range(oname.Name))
MsgBox total
End If
Next oname
End Sub

--


Gary


"Chris Salcedo" wrote in message
oups.com...
I have a sheet that has lots of named ranges. What I need to do is take
each named range and copy it to a new sheet then name the sheet using
the named range. What I dont know how to do is loop through all the
named ranges.

I can do this and it works...

Sub Copy_Range()

ActiveSheet.Range("CPG0162").Select
Selection.Copy
Sheets("Sheet7").Select
Range("A1").Select
ActiveSheet.Paste
End Sub

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default copy all named ranges in a sheet to seperate sheets

This will copy each named range in the workbook to its own new sheet and name
the sheet after the name of the range:

Sub CopyNames()
Dim nm As Name
Dim mySheet As Worksheet
For Each nm In ActiveWorkbook.Names
Range(nm).Copy
Set mySheet = Worksheets.Add(After:=Sheets(Sheets.Count))
mySheet.Name = nm.Name
mySheet.Paste Destination:=Range("A1")
Next nm
Application.CutCopyMode = False
End Sub

HTH,
Dave

"Chris Salcedo" wrote:

I have a sheet that has lots of named ranges. What I need to do is take
each named range and copy it to a new sheet then name the sheet using
the named range. What I dont know how to do is loop through all the
named ranges.

I can do this and it works...

Sub Copy_Range()

ActiveSheet.Range("CPG0162").Select
Selection.Copy
Sheets("Sheet7").Select
Range("A1").Select
ActiveSheet.Paste
End Sub

Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default copy all named ranges in a sheet to seperate sheets

WOW !!!! this is great works fantastic.....

In the words of the scarecrow from OZ "If I only had a brain"...

You da Wiz......

Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default copy all named ranges in a sheet to seperate sheets

Thanks Guys for all the help I have it working now and am adding some
bells and wistles to the code....

Thanks
To all

Chris

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default copy all named ranges in a sheet to seperate sheets

All This stuff is great... Thanks for the help everyone...

Chris

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default copy all named ranges in a sheet to seperate sheets

sorry, for some reason i thought you wanted to sum all of the ranges. don't
know what i was thinking<g

--


Gary


"Chris Salcedo" wrote in message
oups.com...
Thanks Guys for all the help I have it working now and am adding some
bells and wistles to the code....

Thanks
To all

Chris



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy all named ranges in a sheet to seperate sheets

You're welcome.

Chris Salcedo wrote:
WOW !!!! this is great works fantastic.....

In the words of the scarecrow from OZ "If I only had a brain"...

You da Wiz......

Thanks

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
Hyperlink to named ranges and sheets in Excel not working in 2007 Andy Boruta Excel Discussion (Misc queries) 0 December 17th 09 08:53 PM
trying to copy a worksheet containing named ranges to anotherworksheet cil9mxm Excel Worksheet Functions 1 December 3rd 08 06:06 PM
Copy multiple sheets to seperate workbooks MY Excel Discussion (Misc queries) 1 October 15th 08 07:23 PM
Copying named ranges from one sheet to another Mark Stephens Excel Programming 3 August 4th 05 02:54 PM
named ranges and copying sheets to another workbook helpwithXL Excel Programming 1 May 17th 05 04:57 PM


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

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

About Us

"It's about Microsoft Excel"