+ Reply to Thread
Results 1 to 3 of 3

Sheet Navigation

  1. #1
    WayneF
    Guest

    Sheet Navigation


    I have written a macro the selects other sheets and performs some
    actions.

    What i would like to do is return the user back to the original sheet
    they started at. The start sheet can be different and have different names.

    I guess for this i will have to have some VBA code to store the current
    sheet, then i run my code, and then some more code to select the stored
    sheet.

    Can anyone help me out here ?



  2. #2
    JE McGimpsey
    Guest

    Re: Sheet Navigation

    First, in almost every case, selecting other sheets is unnecessary, and
    leads to slower, larger, and harder to understand code.

    For instance, instead of

    Sheets("Sheet1").Select
    Range("A1:J10").Select
    Selection.Copy
    Sheets("Sheet2").Select
    Range("X2").Select
    ActiveSheet.Paste
    Sheets("Sheet1").Select
    Range("A1").Select

    you can use Range objects directly:

    Sheets("Sheet1").Range("A1:J10").Copy Destination:= _
    Sheets("Sheet2").Range("X2")

    which doesn't change the selection at all, is much faster, and there's
    no possibility of confusion over which sheet ActiveSheet.Paste refers to.


    OTOH, if you want to do it the way you proposed:

    Dim rSelection As Range
    Set rSelection = Selection
    'do your code here
    Application.GoTo rSelection


    In article <[email protected]>,
    "WayneF" <[email protected]> wrote:

    >
    > I have written a macro the selects other sheets and performs some
    > actions.
    >
    > What i would like to do is return the user back to the original sheet
    > they started at. The start sheet can be different and have different names.
    >
    > I guess for this i will have to have some VBA code to store the current
    > sheet, then i run my code, and then some more code to select the stored
    > sheet.
    >
    > Can anyone help me out here ?


  3. #3
    Doug
    Guest

    Re: Sheet Navigation

    Try

    Dim sHomeSheetName as String

    sHomeSheetName =Activesheet.Name

    near the start of your macro and

    Sheets(Activesheet.Name).Select

    at the end.

    Doug



    WayneF wrote in message ...
    >
    > I have written a macro the selects other sheets and performs some
    >actions.
    >
    > What i would like to do is return the user back to the original sheet
    >they started at. The start sheet can be different and have different names.
    >
    > I guess for this i will have to have some VBA code to store the current
    >sheet, then i run my code, and then some more code to select the stored
    >sheet.
    >
    > Can anyone help me out here ?
    >
    >




+ 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