Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / January 2006

Tip: Looking for answers? Try searching our database.

Naming ranges as a copy of another sheet

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy Chan - 17 Jan 2006 20:16 GMT
Dear all,

   There are two sheets X and Y in my workbook. On A, there are hundreds of
ranges named locally (i.e. names are like "X!students"). How to write a
macro to name the respective areas in Y with the same local name? For
example, if X!$A$1:$B$4 is named as "X!students", then I want Y!$A$1:$B$4 to
be named as "Y!students".

   Thanks in advance.

Best Regards,
Andy
Dave Peterson - 17 Jan 2006 20:47 GMT
Something like:

Option Explicit
Sub testme01()

   Dim wksMstr As Worksheet
   Dim wksOther As Worksheet
   Dim nm As Name
   Dim testRng As Range
   Dim ExclamPos As Long
       
   Set wksMstr = Worksheets("x z")
   Set wksOther = Worksheets("y z")
   
   For Each nm In wksMstr.Names
       Set testRng = Nothing
       On Error Resume Next
       Set testRng = nm.RefersToRange
       On Error GoTo 0
       
       If testRng Is Nothing Then
           'do nothing
       Else
           ExclamPos = InStr(1, nm.Name, "!", vbTextCompare)
           If ExclamPos > 0 Then
               With wksOther
                   .Names.Add _
                      Name:="'" & .Name & "'" & Mid(nm.Name, ExclamPos),
_                    
                      RefersTo:=.Range(testRng.Address)
               End With
           End If
       End If
   Next nm
End Sub

I'd get a copy of Jan Karel Pieterse's (with Charles Williams and Matthew
Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

> Dear all,
>
[quoted text clipped - 8 lines]
> Best Regards,
> Andy

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.