![]() |
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 |
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 |
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 |
Going back to previous worksheet
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 |
All times are GMT +1. The time now is 11:05 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com