+ Reply to Thread
Results 1 to 3 of 3

Activating the last active worksheet

  1. #1
    Chris M
    Guest

    Activating the last active worksheet

    I hope someone can help me with the following:

    I have a macro that needs to jump between two worksheets. If I'm currently
    in let's say Sheet "A", and then I activate Sheet "B", what code could I use
    to return/reactivate the "last" active worksheet (in this example, go back to
    Sheet "A")? (I can not use any sheet name since this will always be
    different; also, I can't depend on the position or order of the worksheets).
    In other words, I need the code that will take me from my current worksheet
    to the worksheet that was active just prior to the sheet where I am now...

    Thanks for any help!!
    --
    Chris M

  2. #2
    Mike Q.
    Guest

    RE: Activating the last active worksheet

    Hi Chris

    ActiveWindow.ActivateNext
    Brings me back to the last window I was in



    "Chris M" wrote:

    > I hope someone can help me with the following:
    >
    > I have a macro that needs to jump between two worksheets. If I'm currently
    > in let's say Sheet "A", and then I activate Sheet "B", what code could I use
    > to return/reactivate the "last" active worksheet (in this example, go back to
    > Sheet "A")? (I can not use any sheet name since this will always be
    > different; also, I can't depend on the position or order of the worksheets).
    > In other words, I need the code that will take me from my current worksheet
    > to the worksheet that was active just prior to the sheet where I am now...
    >
    > Thanks for any help!!
    > --
    > Chris M


  3. #3
    Norman Jones
    Guest

    Re: Activating the last active worksheet

    Hi Chris,

    You could assign the initial worksheet to an object variable and use the
    variable to return to the sheet. Something like:

    Sub Tester

    Dim WS as Worksheet

    Set WS = ActiveSheet

    ' your code to activate another worksheet
    ' your futher processing code

    WS.activate '<<===== Return to base!
    End sub

    However, vastly perferable would be not to activate various sheets or make
    selections. For example, instead of:

    '---------------------
    Worksheets(2).Activate
    Range("A1"").Select
    ActiveCell.Value = 5
    Worksheets(4).Activate
    Range("D10"").Select
    ActiveCell.Value = 50
    etc.
    '-----------------------

    Equivalent non selection / non activation code might be:


    Worksheets(2).Range("A1"").Value=5
    Worksheets(4).Range("D10"").Value=50


    Not only is the latter code shorter, easier to maintain and faster, but
    there is a reduced processing overhead and you avoid the problem of loosiing
    your way - the subject of your post!


    ---
    Regards,
    Norman



    "Chris M" <[email protected]> wrote in message
    news:[email protected]...
    >I hope someone can help me with the following:
    >
    > I have a macro that needs to jump between two worksheets. If I'm
    > currently
    > in let's say Sheet "A", and then I activate Sheet "B", what code could I
    > use
    > to return/reactivate the "last" active worksheet (in this example, go back
    > to
    > Sheet "A")? (I can not use any sheet name since this will always be
    > different; also, I can't depend on the position or order of the
    > worksheets).
    > In other words, I need the code that will take me from my current
    > worksheet
    > to the worksheet that was active just prior to the sheet where I am now...
    >
    > Thanks for any help!!
    > --
    > Chris M




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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