Hi,
I am trying to write code which looks to see if a sheet exists called 'Copy of System Sheet' and if it does then delete 'System Sheet' and rename the copy as 'System Sheet'. (Copy of System Sheet may be hidden). If sheet 'Copy of System Sheet' does not exist then display the msgbox.
I have the below code which works the first time i press it, but if i run the code twice in a row, the second time it deletes the 'System Sheet'. I cannot figure out why. Any help much appreciated as always.
I am trying to write code which looks to see if a sheet exists called 'Copy of System Sheet' and if it does then delete 'System Sheet' and rename the copy as 'System Sheet'. (Copy of System Sheet may be hidden). If sheet 'Copy of System Sheet' does not exist then display the msgbox.
I have the below code which works the first time i press it, but if i run the code twice in a row, the second time it deletes the 'System Sheet'. I cannot figure out why. Any help much appreciated as always.
Code:
Option Explicit
Dim ws As Worksheet
Dim x As Object
Sub test()
On Error Resume Next
Set ws = Sheets("Copy of System Sheet")
On Error GoTo 0
If Not ws Is Nothing Then
Application.DisplayAlerts = False
Sheets("System Sheet").Delete
Application.DisplayAlerts = True
Sheets("Copy of System Sheet").Visible = True
Sheets("Copy of System Sheet").Select
ActiveSheet.Name = ("System Sheet")
Else
MsgBox "No Copy to Reinstate so i will not delete the System Sheet"
End If
End Sub