Back button Macro?

  • Thread starter Thread starter Fraggs
  • Start date Start date
F

Fraggs

How can I create a generic back button for my workbook, so that it goe
to the last view worksheet? Is this even possible
 
Fraggs,

Put this code in the ThisWorkbook code module

Public prevWs As Worksheet

Private Sub Workbook_Open()
Set prevWs = ActiveSheet
End Sub
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set prevWs = Sh
End Sub


and add this code to a standard code m odule and tie your button to it

Sub PrevSheet()
ThisWorkbook.prevWs.Activate
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
One way:



Code in a regular module:

Public OldSheetName As String

Public mySheetName As String

Sub ReturnToLastSheet()

Worksheets(OldSheetName).Activate

End Sub



Code in the Thisworkbook object:

Private Sub Workbook_Open()

MySheetName = "Sheet1" 'Change as appropriate

End Sub



Private Sub Workbook_SheetActivate(ByVal Sh As Object)

OldSheetName = mySheetName

mySheetName = Sh.Name

End Sub



Then assign the ReturnToLastSheet macro to a button.

HTH Otto
 

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

Back
Top