Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Does this idea help?
Sub lastsht() x = ActiveSheet.Index - 1 'MsgBox x Sheets(x).Select End Sub -- Don Guillett SalesAid Software "Martin Parker" wrote in message ... 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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Go back to the previous excel file | Excel Discussion (Misc queries) | |||
back to previous sheet | Excel Programming | |||
Go back to previous page | Excel Programming | |||
go back/previous cell | Excel Programming | |||
Go back to previous worksheet | New Users to Excel |