SunnySchindler
New Member
- Joined
- Feb 9, 2021
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
At Name creation, Excel defaults to Workbook; which was fine when intended with only one sheet.
Now after finishing all the formulas, I have new need which requires Sheet duplicated to same workbook.
What I need is help on, preferably non-programmatically, is all Names to remain same for maintenance purpose; but the duplicated Names are suffixed with Numbers; I believe the only way is to re-scope all Names from Global to where Sheet .
I have modified following code contributed by someone else who needs the other way round; all Names to be scoped Workbook.
My code to-date shown below
Now after finishing all the formulas, I have new need which requires Sheet duplicated to same workbook.
What I need is help on, preferably non-programmatically, is all Names to remain same for maintenance purpose; but the duplicated Names are suffixed with Numbers; I believe the only way is to re-scope all Names from Global to where Sheet .
I have modified following code contributed by someone else who needs the other way round; all Names to be scoped Workbook.
My code to-date shown below
VBA Code:
Option Explicit
Sub ChangeLocalNameAndOrScope()
'Jul 10, 2015 https://www.mrexcel.com/board/members/joemo.118363/
'I wrote this several years ago and have not used it recently so I would suggest trying it on a copy of your workbook first.
'EDIT: If its not obvious, just enter the name you want w/o any sheet qualifier to get back to global (workbook-level) scope.
'Programmatically change a sheet-level range name and/or scope to a new name and/or scope
'GFIN Sunny modify 230817 - to
' include global names
' suggest new name
Dim ProcName, Message, Title, Default, MyValue, Wsh As Variant
ProcName = "ChangeLocalNameAndOrScope" 'Module Name
With ActiveWorkbook.ActiveSheet
Wsh = .Name
Stop
Message = "Enter a value between 1 and 3" ' Set prompt.
Title = "InputBox Demo" & ProcName ' Set title.
Default = Wsh ' Set default.
' Display dialog box at position 100, 100.
MyValue = InputBox(Message, Title, Default, 100, 100)
'GFIN Sunny modify 230817
Stop
Dim nm As Name, Ans As Integer, newNm As String
Debug.Print ActiveWorkbook.Name
Stop
For Each nm In ActiveWorkbook.Names
'GFIN Sunny modify 230817
Message = "Enter new name - inculde 'Sheet1'! for a local name" ' Set prompt.
Title = "InputBox Demo" & ProcName ' Set title.
'GFIN Sunny modify 230817
If nm.Name Like "*!*" Then 'It is sheet level
' Ans = MsgBox(nm.Name & " is a worksheet level name - do you want to change it?", vbYesNo)
' If Ans = vbYes Then
'
' ' newNm = InputBox("Enter new name - inculde 'Sheet1'! for a local name")
' If newNm = "" Then Exit Sub
' Range(nm.RefersTo).Name = newNm
' nm.Delete
' End If
Else
'Jul 10, 2015 Ans = MsgBox(nm.Name & " is a Workbook level name - do you want to change it?", vbYesNo)
' Stop
Default = Wsh & nm.Name ' Set default.
' Display dialog box at position 100, 100.
MyValue = InputBox(Message, Title, Default, 100, 100)
newNm = MyValue
If Ans = vbYes Then
newNm = InputBox("Enter new name - inculde 'Sheet1'! for a local name")
If newNm = "" Then Exit Sub
Range(nm.RefersTo).Name = newNm
nm.Delete
End If
End If
Next nm
End With
End Sub