+ Reply to Thread
Results 1 to 10 of 10

How to hide sheets conditionally based on cell value

  1. #1
    Registered User
    Join Date
    05-25-2016
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    31

    Question How to hide sheets conditionally based on cell value

    I'm looking for code that will hide one or more worksheets based on a cell value in Sheet1. For example if cell A2 (in Sheet1) = 2, then hide Sheet5 and Sheet6; again if A2 = 3, then hide Sheet6.

    I'm a newbie and have been trying for the code for last few days but failed. So I'm looking for help from experts here.

    Thanks in advance.
    Last edited by masud_jahan; 05-25-2016 at 11:21 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to hide sheets conditionally based on cell value

    This matches your description as an example, but note that you didn't say when you want to unhide sheets. This code must be put in the code module for Sheet1.
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to hide sheets conditionally based on cell value

    Hi,

    Maybe

    Please Login or Register  to view this content.
    Where Sheet1 & Sheet2 are the VBA code names
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  4. #4
    Registered User
    Join Date
    05-25-2016
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    31

    Re: How to hide sheets conditionally based on cell value

    Thanks Jeff . It can hide the sheets successfully but the problem now to unhide the sheets as you pointed out. I need the sheets to unhide if else (if A2 not equal to 2 or 3)

  5. #5
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: How to hide sheets conditionally based on cell value

    EXCEL's BUILT IN FEATURE
    Do you know that excel has a built in feature for this ? On the View tab there is a function called "Custom Views". With custom views you set up your sheets they way you want to view them ... or hide them ... and give that view a name. Then whenever you want that view to be used you just select the name of the view from the drop down list.
    If you are using it a lot the drop down list can be moved to your home tab.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: How to hide sheets conditionally based on cell value

    How are you going to change A2 if the sheet is hidden? Is A2 a formula driven by other cells?

  7. #7
    Registered User
    Join Date
    05-25-2016
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    31

    Re: How to hide sheets conditionally based on cell value

    Thanks Richard for your reply. A2 is a cell in Sheet1 which will be changed manually. I need to hide/unhide Sheet5 & Sheet6 only not Sheet1.
    Last edited by masud_jahan; 05-25-2016 at 12:00 PM.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: How to hide sheets conditionally based on cell value

    Try this to unhide sheets as needed:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    05-25-2016
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    31

    Re: How to hide sheets conditionally based on cell value

    Thanks a lot Jeff
    The unhide issue is solved now.

  10. #10
    Registered User
    Join Date
    05-25-2016
    Location
    Dhaka, Bangladesh
    MS-Off Ver
    2010
    Posts
    31

    Re: How to hide sheets conditionally based on cell value

    Quote Originally Posted by 6StringJazzer View Post
    Try this to unhide sheets as needed:

    Please Login or Register  to view this content.
    I modified your code little like below as I modified my condition as well and its working great:
    Please Login or Register  to view this content.
    Last edited by masud_jahan; 05-28-2016 at 12:26 AM.

+ 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. Conditionally hide row based on specific text in a cell
    By Lorbiculous in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2015, 06:19 PM
  2. Conditionally hide/unhide worksheets based on cell values
    By David O'Riley in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-05-2015, 09:47 AM
  3. Conditionally hide rows based on cell value
    By AFrenkiel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-23-2013, 04:11 AM
  4. [SOLVED] hide sheets based on the cell value
    By sknalodz in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-24-2013, 01:43 AM
  5. Conditionally Hide Rows Based on cell
    By Lulidec in forum Excel General
    Replies: 1
    Last Post: 01-09-2013, 01:29 PM
  6. Conditionally Hide Sheets
    By amotto11 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2012, 06:05 PM
  7. Conditionally Hide Columns based on cell result
    By montego in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 01-08-2012, 06:24 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