Worksheet Command Buttons


Posted by Don on February 09, 2001 7:51 AM

Can antone help? Ihave a workbook that contains 6 worksheets. The first 5 sheets contain data that is plotted on a chart on sheet6. I put a command button on the first 5 sheets that allows you to view sheet6 using the code:Worksheets("Sheet6").Activate. I would like to put a command buttom on sheet6 that would take you back to you sheet you previously came from.For example, I you were on sheet3 and clicked the command button to view sheet6, I would want the command button on sheet6 to take you back to sheet3(or whatever sheet you previously came from. I need help with the code. Thanks in advance



Posted by Celia on February 09, 2001 7:18 PM


Don
There's probably a better way to code it, but this should work :-

Option Explicit
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Call SetVariable
Set previousWS = Sh
End Sub

Option Explicit
Public previousWS As Worksheet
Sub SetVariable()
Set previousWS = ActiveSheet
End Sub
Sub ActivatePreviousWS()
previousWS.Select
End Sub

Celia