last active sheet

dcompagnone

Board Regular
Joined
Dec 14, 2007
Messages
119
Hi,

Anyone help me with a small piece of code that will allow me to add a 'retur to last active sheet' type functionality to excel?

For example:

I have sheets 1 - 3 that contains all my data. from each of those, there is a link to a document on sheet 4 which you can populte, print and email. What I want to be able to do is then have a button that allows the user to go back to the sheet they came from rather than having to search through tabs for it.


This is a simplified version of my doc. I actually have nearly 100 sheets of data all linking to my 'printable/emailable' sheet.

Help appreciated.

Dom
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
just an idea out there.

You could declare a public variable in VBA (Dim prevWorksheet As Worksheet)
and set it as the worksheet with the event worksheet_Select

Then in your master sheet, you can activate it like (prevWorksheet.Activate)
and it should automatically bring the user back to his/her previous worksheet.
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Dom

You could do this with code - insert a standard module in your workbook (via the VBE) and place the following code inside it:

Code:
Public shtNm As String
Sub select_shtNm()
On Error Resume Next
Sheets(shtNm).Select
End Sub
Then place the following in the ThisWorkbook module of the workbook:

Code:
Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
shtNm = Sh.Name
End Sub
And then you just need to assign the macro select_shtNm to a button or to a shortcut key.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,532
Messages
5,511,874
Members
408,867
Latest member
Ranjeet yamgekar

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top