Excel vba: Select cell A1 on all sheets before you close a workbook
This post demonstrates how to automatically select cell A1 on each sheet in a workbook before you close a workbook. The vba code also makes cell A1 the upper left cell on all sheets.
VBA code
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sht As Worksheet, csheet As Worksheet
Application.ScreenUpdating = False
Set csheet = ActiveSheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Visible Then
sht.Activate
Range("A1").Select
ActiveWindow.ScrollRow = 1
ActiveWindow.ScrollColumn = 1
End If
Next sht
csheet.Activate
Application.ScreenUpdating = True
End SubWhere to copy the code
- Press Alt-F11 to open visual basic editor
- Double click ThisWorkbook in project explorer.
Ctrl + R opens project explorer.

- Copy and paste above vba code.
- Exit visual basic editor
Download excel file
Reset selection to A1.xlsm
Excel 2007 Macro-Enabled Workbook *.xlsm
Related posts:
Create links to all sheets in a workbook
Excel 2007 vba: Create a custom-made item on the shortcut menu
List all open workbooks and corresponding sheets (vba)
Get data from same cell references of every sheet in workbook


















thanks... works great!