View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Rename all named ranges?

when i go to insert/name/define and click on a name, i get something like the
following in the refers to box
=Sheet1!$D$8:$G$13
what do you see? all that line of code does is extract the sheet name from the
named range, "sheet1"

maybe give an example of your named ranges and a range it refers to.


--


Gary


"Johan" wrote in message
oups.com...
Thanks for helping me, I think the solution is near.

Dave peterson wrote "But you never shared the rules or list for what
names should be replaced"

I would like all the names to be replaced and I'm only using names in
the workbook (not in code).
I'm using names only for ranges, not dynamic ranges or formulas.

I tried Gary's code but I got this error message:
" subscript out of range"

Sub RenameRanges()
Dim nm As Name
Dim sname As String
Dim v1 As String
Dim ws As Worksheet
Dim NewName As String
For Each nm In ThisWorkbook.Names
sname = Mid(nm, 2, InStr(nm, "!") - 2)
v1 = "r_" & nm.Name
ActiveWorkbook.Names.Add Name:=v1, RefersTo:=nm
With Worksheets(sname).UsedRange
''''''''''''''''''''''''''''here I get " subscript out of range"
.Replace what:=nm.Name, replacement:=v1, _
SearchOrder:=xlByColumns, MatchCase:=False
End With
nm.Delete
Next
End Sub

I have tried to modife the code, but I han't got it 100% right. Any
ideas what I should do?

Thanks,

Johan