View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
ketut ketut is offline
external usenet poster
 
Posts: 4
Default Excel- Go to Previous Sheet

On 2 July, 12:19, Mike H wrote:
Hi,

This requires 2 bits of code.
Alt+F11 to open VB editor and double click 'Thisworkbook' and paste this
code in on the right

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
lastsheet = Sh.Name
End Sub

Then right click 'ThisWorkbook' and insert module and paste this code in

Public lastsheet As String
Sub Select_Last()
Sheets(lastsheet).Select
End Sub

When ever a user changes sheets the name of the last sheet is now held in
the variable 'Lastsheet' so if you assign a shortcut or button to the code
then the last used sheet will be selected.

Mike

"ketut" wrote:
Hi all,


Please help. I am in need to find the VBA code to enable me to set a
Go to previous sheet button on one of the sheets in my report.
The report has 10 sheets. 1 of these sheets can be accessed from any
of the other 9, but I would like whoever access it can go back to
where they were but a click of a button. Please help me and tell me
how can do that?
I can copy and past the code to excel provide you tell me what it
is....


Thank you so much in advance guys.
( I know nothing about VBA or codings).


Hi Mike,
Thank you so much for your prompt response. that was very quick.
I have done what you said, however I have just 1 more question:
what should I replace "Sh.name" with because I keep getting a
"subscript out of range error". when I click on Debug the highlighted
area is "Sheets(lastsheet).Select"
many thanks in advance.
Kal