PC Review


Reply
Thread Tools Rate Thread

change range names on a particular sheet

 
 
Ken
Guest
Posts: n/a
 
      1st May 2007
I use the following code to change the names of all the rangenames in
a particular workbook:

Sub chng()
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If Left(nm.Name, 3) = "FFG" Then
nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
End If
Next nm
End Sub

Now, because I copied a sheet with a whole lot of rangenames, I have a
sheet with local rangenames that are the same as the global rangenames
on the original sheet. I need to modify the code, so it only changes
rangenames that are local to a particular sheet. Is there a property
of Names that I can use to limit the name changing to rangenames local
to a particular worksheet?

Thanks

Ken

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?=
Guest
Posts: n/a
 
      1st May 2007
A name that is local to a worksheet will have the worksheet name as part of
the name. You can search the name for "!" to determine if it's local

Sub chng()
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If InStr(1, nm.Name, "!") > 0 Then
If Left(nm.Name, 3) = "FFG" Then
nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
End If
End If
Next nm
End Sub

or you can also check the Parent's name. If it's equal to the workbook name,
then it's not local.

Sub chng2()
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If nm.Parent.Name <> ThisWorkbook.Name Then
If Left(nm.Name, 3) = "FFG" Then
nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
End If
End If
Next nm
End Sub


--
Hope that helps.

Vergel Adriano


"Ken" wrote:

> I use the following code to change the names of all the rangenames in
> a particular workbook:
>
> Sub chng()
> Dim nm As Name
> For Each nm In ActiveWorkbook.Names
> If Left(nm.Name, 3) = "FFG" Then
> nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
> End If
> Next nm
> End Sub
>
> Now, because I copied a sheet with a whole lot of rangenames, I have a
> sheet with local rangenames that are the same as the global rangenames
> on the original sheet. I need to modify the code, so it only changes
> rangenames that are local to a particular sheet. Is there a property
> of Names that I can use to limit the name changing to rangenames local
> to a particular worksheet?
>
> Thanks
>
> Ken
>
>

 
Reply With Quote
 
Ken
Guest
Posts: n/a
 
      1st May 2007
Vergel

Thanks to your timely help I got it to work. I am not exactly sure
what was going on though.

I used this code:

Sub chng()
Dim nm As Name
For Each nm In ActiveWorkbook.Names
If InStr(1, nm.Name, "!") > 0 Then
If Left(nm.Name, 6) = "DDG!CG" Then
nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 6)
End If
End If
Next nm
End Sub

It crashed most of the time, and pointed me to the first End If
statement, with no clue what the problem was. When I set a break
point on the nm.Name= line and stepped through, it never crashed; but,
it never finished. It did the conversions I wanted, but, kept going
through the Names over and over until I stopped it. But, when I
stopped it, everything was changed. I used Jan Karel Pieterse' slick
Name Manager Add-in to convert the modified local range names to
global, and I am all set.

Thanks again

Ken

On May 1, 2:52 pm, Vergel Adriano
<VergelAdri...@discussions.microsoft.com> wrote:
> A name that is local to a worksheet will have the worksheet name as part of
> the name. You can search the name for "!" to determine if it's local
>
> Sub chng()
> Dim nm As Name
> For Each nm In ActiveWorkbook.Names
> If InStr(1, nm.Name, "!") > 0 Then
> If Left(nm.Name, 3) = "FFG" Then
> nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
> End If
> End If
> Next nm
> End Sub
>
> or you can also check the Parent's name. If it's equal to the workbook name,
> then it's not local.
>
> Sub chng2()
> Dim nm As Name
> For Each nm In ActiveWorkbook.Names
> If nm.Parent.Name <> ThisWorkbook.Name Then
> If Left(nm.Name, 3) = "FFG" Then
> nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
> End If
> End If
> Next nm
> End Sub
>
> --
> Hope that helps.
>
> Vergel Adriano
>
>
>
> "Ken" wrote:
> > I use the following code to change the names of all the rangenames in
> > a particular workbook:

>
> > Sub chng()
> > Dim nm As Name
> > For Each nm In ActiveWorkbook.Names
> > If Left(nm.Name, 3) = "FFG" Then
> > nm.Name = "DDG" & Right(nm.Name, Len(nm.Name) - 3)
> > End If
> > Next nm
> > End Sub

>
> > Now, because I copied a sheet with a whole lot of rangenames, I have a
> > sheet with local rangenames that are the same as the global rangenames
> > on the original sheet. I need to modify the code, so it only changes
> > rangenames that are local to a particular sheet. Is there a property
> > of Names that I can use to limit the name changing to rangenames local
> > to a particular worksheet?

>
> > Thanks

>
> > Ken- Hide quoted text -

>
> - Show quoted text -



 
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
Range names vs Sheet name Hennie Neuhoff Microsoft Excel Programming 11 26th Aug 2008 12:13 PM
How to change XL sheet names from cell range =?Utf-8?B?QmlsYQ==?= Microsoft Excel Programming 7 16th Mar 2007 02:03 PM
Automatically entering sheet names into a range of cells on one sheet u539771 Microsoft Excel Worksheet Functions 2 23rd Jun 2004 12:54 PM
Range Names From one sheet to Another Neil Microsoft Excel Programming 3 19th Feb 2004 11:01 AM
Range Names associated with Sheet Name Chris Gorham Microsoft Excel Programming 2 17th Jan 2004 02:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 AM.