Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Going back to previous worksheet

Hi,

I have several worksheets in a workbook, each with a commandbutton which has
the same function (to take the user back to the previously active worksheet).
What I'm trying to achieve is when the user clicks the commandbutton, the
user is taken back to the previously active worksheet i.e. if user is
currently on sheet 3 and was previously working on sheet 2, when the
commandbutton is clicked on sheet 3, the user is automatically transfered to
sheet 2 and so on etc etc.

Can anyone help?

Kind regards
Martin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Going back to previous worksheet

Firstly capture the name of the sheet you just left and write it away. In
this case to A1 on sheet 1.

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Worksheets("Sheet1").Cells(1, 1) = Sh.Name
End Sub

The for your button use this code

Sub Button2_Click()
Name = Worksheets("Sheet1").Cells(1, 1).Value
Worksheets(Name).Select
End Sub


Mike

"Martin Parker" wrote:

Hi,

I have several worksheets in a workbook, each with a commandbutton which has
the same function (to take the user back to the previously active worksheet).
What I'm trying to achieve is when the user clicks the commandbutton, the
user is taken back to the previously active worksheet i.e. if user is
currently on sheet 3 and was previously working on sheet 2, when the
commandbutton is clicked on sheet 3, the user is automatically transfered to
sheet 2 and so on etc etc.

Can anyone help?

Kind regards
Martin

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Going back to previous worksheet

In the ThisWorkbook code module, paste this:

Private oldSht As Worksheet

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Set oldSht = Sh
End Sub

Then, assign this macro to your buttons:

Public Sub GoBack()
oldSht.Activate
End Sub






--
Hope that helps.

Vergel Adriano


"Martin Parker" wrote:

Hi,

I have several worksheets in a workbook, each with a commandbutton which has
the same function (to take the user back to the previously active worksheet).
What I'm trying to achieve is when the user clicks the commandbutton, the
user is taken back to the previously active worksheet i.e. if user is
currently on sheet 3 and was previously working on sheet 2, when the
commandbutton is clicked on sheet 3, the user is automatically transfered to
sheet 2 and so on etc etc.

Can anyone help?

Kind regards
Martin

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Go back to the previous excel file houghi Excel Discussion (Misc queries) 2 March 6th 09 04:25 PM
back to previous sheet Miri Excel Programming 1 January 29th 07 07:07 AM
Go back to previous page Gary''s Student Excel Programming 0 December 5th 06 09:02 PM
go back/previous cell jasminesy Excel Programming 4 May 24th 06 04:02 PM
Go back to previous worksheet BarryL New Users to Excel 2 May 5th 05 01:38 AM


All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"