April 23, 2015
Hi there,
Does anyone know of a keyboard short cut or maybe a bit of VBA that allows you to move between the worksheet you are on and the last worksheet you were on within a workbook? I have a couple of workbooks with a lot of tabs and this would be a really handy feature to have.
Alan
VIP
Trusted Members
December 7, 2016
September 9, 2020
Hi Alan,
Here is a VBA solution.
1. In ThisWorkbook, you paste the following two codes.
The first code allows you to initialize the shortcut keys with the main macro 'Select_Last_Sheet'.
For the example, I have chosen the following combination : CTRL + ALT + J
Private Sub Workbook_Open()
LastSheet = ActiveSheet.Name
Application.OnKey "^%j", "Select_Last"
End Sub
The second code retrieves the name of the last sheet
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
LastSheet = Sh.Name
End Sub
2. Then, you create a module in which you put this code. It allows you to teleport to the desired tab.
Public LastSheet As String
Sub Select_Last_Sheet()
Application.Sheets(LastSheet).Select
End Sub
Info : the table below gives an overview of the syntax to be used. There are many others.
Key | Key code |
Capital | + |
Control | ^ |
Alt | % |
Suppr | {DELETE} |
Backspace | {BACKSPACE} |
BR,
Lionel
1 Guest(s)