View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default change range names on a particular sheet

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