+ Reply to Thread
Results 1 to 7 of 7

Returning to initial worksheet after Macro changes worksheet

  1. #1
    Registered User
    Join Date
    08-04-2015
    Location
    Harpenden
    MS-Off Ver
    97
    Posts
    7

    Question Returning to initial worksheet after Macro changes worksheet

    Hi Folks,
    I have a macro that hides certain rows in each of 4 worksheets. Currently it always remains on the last worksheet that was selected. I would like it to return to the worksheet from which the macro was invoked - it could be any of them. I just don't know enough about this VB stuff..... Any ideas?

    Regards,
    Peter

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Returning to initial worksheet after Macro changes worksheet

    Got an example workbook?

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Returning to initial worksheet after Macro changes worksheet

    Well, two ways.

    1. Define a worksheet object variable and use, say,
    Please Login or Register  to view this content.
    . Then, at the end, use
    Please Login or Register  to view this content.
    2. Don't select the worksheets. Use With ... End With to create a "With block" and then refer to the cells/rows/columns using the reference. Much more efficient.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    08-04-2015
    Location
    Harpenden
    MS-Off Ver
    97
    Posts
    7

    Re: Returning to initial worksheet after Macro changes worksheet

    Quote Originally Posted by Philb1 View Post
    Got an example workbook?
    Yes, but I don't know how to attach or send it.

    Peter

  5. #5
    Registered User
    Join Date
    08-04-2015
    Location
    Harpenden
    MS-Off Ver
    97
    Posts
    7

    Re: Returning to initial worksheet after Macro changes worksheet

    The Set.WSa works well - thanks.

    I will try the second recommendation sometime!

    Regards,

    Peter

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,447

    Re: Returning to initial worksheet after Macro changes worksheet

    You're welcome.



    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Valued Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2019
    Posts
    716

    Re: Returning to initial worksheet after Macro changes worksheet

    Quote Originally Posted by Peterhmg View Post
    Yes, but I don't know how to attach or send it.

    Peter
    Hi peter
    Go advanced, click the paper clip icon & follow the prompts is the way it's supposed to work. I haven't been able to upload a file here for months now coz it doesn't work, I have to click the link icon & use a dropbox link

+ 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. Replies: 3
    Last Post: 01-20-2014, 11:04 PM
  2. [SOLVED] Macro/VBA code to Copy data from primary worksheet to a worksheet opened by macro
    By MHamid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2013, 11:10 AM
  3. Excel 2010 Macro to copy worksheet, update formula and rename worksheet
    By madmak0203 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:18 PM
  4. Replies: 1
    Last Post: 08-29-2012, 07:11 PM
  5. Returning Scrollbar to Initial Position
    By Mordred in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-04-2011, 03:11 PM
  6. [SOLVED] how can i define initial worksheet
    By Miqueias Lucas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2005, 02:05 PM
  7. [SOLVED] initial worksheet
    By Miqueias Lucas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2005, 01:05 PM

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