+ Reply to Thread
Results 1 to 7 of 7

Hide/ Unhide Sheets with macro

  1. #1
    Registered User
    Join Date
    10-23-2008
    Location
    Denver
    Posts
    31

    Hide/ Unhide Sheets with macro

    I want to run 2 different macros:

    Macro 1- hides Sheet1 and unhides Sheet2
    Macro 2- Hides Sheet2 and unhides Sheet1

    I used the macro recorder to attempt to make this work but am running into a problem if Macro1 is run two times consecutively. In this situation the macro displays a debugging error b/c Sheet1 is hidden. Is there a way to get around this...possibly using an if then statement?

    Cheers-
    C

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This macro should toggle the sheets visibility

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    10-23-2008
    Location
    Denver
    Posts
    31
    RoyUK- This does toggle between the worksheets based on which one is hidden. I don't need them to toggle since I will assign 2 different Macros depending on what sheets need to be hidden.

    I found the best way for this to work for my purposes is to make both sheets visible within the macro and then hide the required worksheet as follows:
    Please Login or Register  to view this content.
    Can you please mark this as "SOLVED"?

    Cheers-
    C
    Last edited by royUK; 11-10-2008 at 01:14 PM.

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please use Code Tags when posting code.

    I can't see the reasoning behind having two macros when one will do

  6. #6
    Registered User
    Join Date
    10-23-2008
    Location
    Denver
    Posts
    31
    My apologies. I will use code tags in the future.

    I need 2 macros because i don't want to toggle between the 2 sheets based on which one is visible. I want to be able to always hide "Sheet1" and unhide
    Sheet 2" if i push a button assigned to the macro and always hide "Sheet2" and unhide "Sheet1" if another button assigned to the 2nd macro is pushed. Based on this info am I going about this the correct way?

    Thanks again for all your help!

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try this

    Please Login or Register  to view this content.

+ 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