For that you need to keep track of the previously active sheet, and to do this you can make use of the SheetActivate event of the Workbook, which passes a reference to the newly activated sheet.
You need to store this and the previous value, so that you can activate the appropriate sheet. Here is some code to go in the Wokbook to store those values:
VB Code:
Dim oCurrSheet As Worksheet
Dim oPrevSheet As Worksheet
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Set oPrevSheet = oCurrSheet
Set oCurrSheet = Sh
End Sub
In order to activate the previous sheet you just need oPrevSheet.Activate, however this will fire the SheetActivate event again - so then the previous sheet is where you just came from.
If this is a problem, you need to make amendments like this (you now need to call ActivatePrevSheet instead):
VB Code:
Dim oCurrSheet As Worksheet
Dim oPrevSheet As Worksheet
Dim bIsActivating As Boolean
Sub ActivatePrevSheet()
bIsActivating = True
oPrevSheet.Activate
bIsActivating = False
End Sub
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Not (bIsActivating) Then
Set oPrevSheet = oCurrSheet
Set oCurrSheet = Sh
End If
End Sub