Return to starting point

  • Thread starter Patrick C. Simonds
  • Start date
P

Patrick C. Simonds

Any way that the code below can be made to return me to the worksheet and
cell were the code was triggered?

Sub HolidayRemove()

'Code provided b Mike H

Application.ScreenUpdating = False

On Error GoTo ErrorHandler

For n = 1 To Sheets.Count
If Sheets(n).Name <> "Holidays" Then
Sheets(n).Select
Sheets(n).Unprotect
With Sheets(n)
Range("S5").Activate
ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""
Sheets(n).Protect
End With
End If
Next n

ErrorHandler:

Application.ScreenUpdating = True

End Sub
 
G

Gary''s Student

We store the sheet & cell and then return there:

Sub HolidayRemove()
Dim oldSheet As Worksheet
Dim oldCell As String
Set oldSheet = ActiveSheet
oldCell = ActiveCell.Address
'Code provided b Mike H

Application.ScreenUpdating = False

On Error GoTo ErrorHandler

For n = 1 To Sheets.Count
If Sheets(n).Name <> "Holidays" Then
Sheets(n).Select
Sheets(n).Unprotect
With Sheets(n)
Range("S5").Activate
ActiveSheet.Shapes.SelectAll
Selection.Delete
Range("K1").Value = ""
Sheets(n).Protect
End With
End If
Next n

ErrorHandler:

Application.ScreenUpdating = True
oldSheet.Activate
Range(oldCell).Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top