ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return to starting point (https://www.excelbanter.com/excel-programming/420948-return-starting-point.html)

Patrick C. Simonds

Return to starting point
 
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



Gary''s Student

Return to starting point
 
We store the sheet & cell and then return the

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

--
Gary''s Student - gsnu2007k


"Patrick C. Simonds" wrote:

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





All times are GMT +1. The time now is 04:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com