For a number of reasons, my code needs to
1) duplicate a sheet (sheet1)
2) work on duplicated sheet (sheet1 (2))
3) at the end, delete original sheet1 and rename the duplicated sheet to sheet1
Unfortunately, there is a third sheet with fixed references to cells in sheet1 (with fixed I mean that the references are to cells not interested in the work done in point 2), and these references disappear (#ref).
Trying to find a solution, I discovered that the sheets have an internal name (codename) in addition to the external name that appears on the tabs. So I thought that maybe the references need that name as well. Therefore, I modified my code (see below) to save the original sheet1 codename and restore it to the "new" renamed sheet1. Even if the code seems to work (sheet1 gets indeed the old codename) the references still disappear. Is it really impossible to restore the references to a deleted sheet, after reconstructing it?
Thanks
Robert
Code:
Sub Macro1()
'
' Macro1 Macro
'
Dim LastRow, I, Index As Long
Dim ActualCodename, ActualCodename2 As String
'create a copy of Banca
Sheets("Banca 2015").Select
' get the codename for "Banca 2015" to be used later
ActualCodename = Sheets("Banca 2015").CodeName
Application.DisplayAlerts = False
Sheets("Banca 2015").Copy Before:=Sheets(3)
Application.DisplayAlerts = True
' working code follows...
'***************************************+
' delete old sheet and rename new one
Application.DisplayAlerts = False
Sheets("Banca 2015").Delete
Application.DisplayAlerts = True
'Rename sheet (EXTERNAL name)
Sheets("Banca 2015 (2)").Name = "Banca 2015"
'get codename of this renamed sheet
ActualCodename2 = Sheets("Banca 2015").CodeName
' restore original codename saved at the beginning...
With ActiveWorkbook
.VBProject.VBComponents(ActualCodename2).Properties("_CodeName").Value = ActualCodename
End With
End Sub
Bookmarks