+ Reply to Thread
Results 1 to 3 of 3

back to previous active sheet ?

Hybrid View

Lukael back to previous active sheet... 08-22-2014, 01:44 PM
Jakobshavn Re: back to previous active... 08-22-2014, 03:18 PM
Lukael Re: back to previous active... 08-22-2014, 04:45 PM
  1. #1
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    back to previous active sheet ?

    Hi,

    I'm listing through sheets and have Sheet2 for drop-down lists.

    Sheet2 is not visible, but when I click on Cmdbutton It appears so that I can change values in drop-downs. When I hide Sheet2 again, I want to be back on sheet before Sheet2.

    My code for open and close sheet2 :

    Sub open_sheet()
    
    Worksheets("Sheet2").Activate
    Worksheets("Sheet2").Visible = True
    
    End Sub
    
    Sub close_sheet()
    
    Worksheets("Sheet2").Visible = False
    End Sub
    How can I do that ?

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: back to previous active sheet ?

    You need to "remember" where you came from. In each sheet, except Sheet2, include the following event macro:

    Private Sub Worksheet_Deactivate()
        Set Oldsheet = Me
    End Sub
    At the top of a standard module, include this single line:

    Public Oldsheet As Worksheet
    So whenever you move from worksheet to worksheet, OldSheet will remember where you came from.

    Finally in a standard module:

    Sub close_sheet()
        Worksheets("Sheet2").Visible = False
        Oldsheet.Activate
    End Sub
    Gary's Student

  3. #3
    Forum Contributor
    Join Date
    02-09-2014
    Location
    Kamnik, Slovenia
    MS-Off Ver
    Excel 2010
    Posts
    693

    Re: back to previous active sheet ?

    Hi Jakobshavn,

    It works !

    Thanks for help & explanation

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to go back to the last active sheet and hide the active sheet
    By yatahaze in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 08:18 AM
  2. Replies: 1
    Last Post: 07-07-2014, 09:19 AM
  3. [SOLVED] Go back to previous active sheet (Excel 2007)
    By JawD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2012, 08:00 AM
  4. VBA code to open next sheet or go back to previous
    By ABSTRAKTUS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-14-2010, 07:21 AM
  5. Hyperlink refers back to previous sheet?
    By simonwilliams in forum Excel General
    Replies: 8
    Last Post: 12-09-2009, 07:23 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1