PC Review


Reply
Thread Tools Rate Thread

Copy worksheet with named ranges to new workbook and keep names in

 
 
Sandy
Guest
Posts: n/a
 
      11th Jul 2008
Hello -

I have a worksheet in one work book with a large number of named ranges. I
want to use these named ranges in another workbook.

How do I copy a group of named ranges and paste them into the new worksheet
and still preserve the name definitions in the new worksheet?

Many thanks
sandra
 
Reply With Quote
 
 
 
 
Mike H.
Guest
Posts: n/a
 
      11th Jul 2008
This is one way that would work:
Obviously, you'd have to adjust named range names and sheet names as
appropriate.


Option Explicit
Option Base 1

Sub Doit()
Dim MyEntries As String
Dim OrigEntries As String
Dim PasteRange As Range
Dim toprange As Variant
Dim rowcount As Long
Dim ColCount As Long
Dim TopRow As Long
Dim TOpCol As Long

OrigEntries = ActiveWorkbook.Name
Range("area1").Select
Selection.Copy
Workbooks.Add Template:="Workbook"
MyEntries = ActiveWorkbook.Name
Sheets("sheet1").Select
ActiveSheet.Paste
Let TopRow = ActiveCell.Row
Let TOpCol = ActiveCell.Column
Let rowcount = Selection.Rows.Count
Let ColCount = Selection.Columns.Count
ActiveWorkbook.Names.Add Name:="area1", RefersToR1C1:="=Sheet1!" & "R" &
TopRow & "C" & TOpCol & ":R" & rowcount - TopRow + 1 & "C" & ColCount -
TOpCol + 1

Windows(OrigEntries).Activate
Range("area2").Select
Selection.Copy
Windows(MyEntries).Activate
Cells(10, 1).Select
ActiveSheet.Paste
'Let PasteRange = ActiveSheet.Range
Let TopRow = ActiveCell.Row
Let TOpCol = ActiveCell.Column
Let rowcount = Selection.Rows.Count
Let ColCount = Selection.Columns.Count
ActiveWorkbook.Names.Add Name:="area2", RefersToR1C1:="=Sheet1!" & "R" &
TopRow & "C" & TOpCol & ":R" & rowcount + TopRow - 1 & "C" & ColCount +
TOpCol - 1


End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting named ranges on a worksheet (not workbook) BRC Microsoft Excel Programming 5 10th Jan 2010 12:38 AM
How can I delete all named ranges in a workbook or worksheet? AZSteve Microsoft Excel Programming 5 21st Oct 2009 06:48 PM
Copy worksheet with named ranges to new workbook and keep names Sandy Microsoft Excel Worksheet Functions 0 11th Jul 2008 04:37 PM
Named ranges scope / workbook/worksheet level named ranges- changeswith variable use... christian_spaceman Microsoft Excel Programming 3 24th Dec 2007 01:15 PM
named ranges at workbook and worksheet levels mark kubicki Microsoft Excel Programming 5 15th Sep 2004 10:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:07 PM.