+ Reply to Thread
Results 1 to 5 of 5

How To Hide/Unhide sheets based on a button click

Hybrid View

m2som How To Hide/Unhide sheets... 05-14-2017, 06:28 PM
alansidman Re: How To Hide/Unhide ... 05-14-2017, 07:20 PM
mike7952 Re: How To Hide/Unhide ... 05-14-2017, 07:21 PM
Logit Re: How To Hide/Unhide ... 05-14-2017, 07:30 PM
Norie Re: How To Hide/Unhide ... 05-14-2017, 07:54 PM
  1. #1
    Registered User
    Join Date
    03-23-2013
    Location
    egypt
    MS-Off Ver
    Excel 2007
    Posts
    30

    How To Hide/Unhide sheets based on a button click

    Hello Guys, Please help me with the attached sheet, As I want to use the two buttons in the cover sheet to hide and unhide sheets on click, Like If I press case 1 then case 1 sheets will be shown and case two sheets will be hidden. Also I need to disable unhiding sheets to be only by pressing the button.

    Regards
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,714

    Re: How To Hide/Unhide sheets based on a button click

    Try this:
    Option Explicit
    
    Sub Oval1_Click()
    Sheets("Case 1 Sheet").Visible = False
    Sheets("Case 1 Sheet 2").Visible = False
    Sheets("Case 2 Sheet").Visible = True
    Sheets("Case 2 Sheet 2").Visible = True
    End Sub
    Sub Oval2_Click()
    Sheets("Case 1 Sheet").Visible = True
    Sheets("Case 1 Sheet 2").Visible = True
    Sheets("Case 2 Sheet").Visible = False
    Sheets("Case 2 Sheet 2").Visible = False
    End Sub
    https://www.mrexcel.com/forum/excel-...e-control.html
    Last edited by alansidman; 05-14-2017 at 07:27 PM.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: How To Hide/Unhide sheets based on a button click

    One way

    For Oval 1 macro
    Const shCover As String = "Cover"
    Sub Case1()
     Dim ws As Worksheet
     Application.ScreenUpdating = False
     For Each ws In Worksheets
        If ws.Name <> shCover Then
            If ws.Name Like "Case 1*" Then
                ws.Visible = xlSheetVisible
            Else
                ws.Visible = xlSheetVeryHidden
            End If
        End If
     Next
     Worksheets(shCover).Select
     Application.ScreenUpdating = True
    End Sub
    For Oval 2 macro
    Sub Case2()
     Dim ws As Worksheet
     Application.ScreenUpdating = False
     For Each ws In Worksheets
        If ws.Name <> shCover Then
            If ws.Name Like "Case 2*" Then
                ws.Visible = xlSheetVisible
            Else
                ws.Visible = xlSheetVeryHidden
            End If
        End If
     Next
     Worksheets(shCover).Select
     Application.ScreenUpdating = True
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,415

    Re: How To Hide/Unhide sheets based on a button click

    .
    .
    And still one more way :

    Option Explicit
    
    Sub ShowHideWorksheets1()
    Dim Cell As Range
    For Each Cell In Range("A1:A2")
        ActiveWorkbook.Worksheets(Cell.Value).Visible = Not ActiveWorkbook.Worksheets(Cell.Value).Visible
    Next Cell
    End Sub
    
    Sub ShowHideWorksheets2()
    Dim Cell As Range
    For Each Cell In Range("B1:B2")
        ActiveWorkbook.Worksheets(Cell.Value).Visible = Not ActiveWorkbook.Worksheets(Cell.Value).Visible
    Next Cell
    End Sub
    Attached Files Attached Files

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: How To Hide/Unhide sheets based on a button click

    Was going to post some code for this but it's a bit late.

    Anyway just curious, couldn't Application.Caller be used here?
    If posting code please use code tags, see here.

+ 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. Toggle Button to hide unhide sheets
    By 95marine in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2017, 04:46 PM
  2. Required macro with button/option to hide unhide several sheets
    By vishpuj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-25-2015, 06:43 AM
  3. [SOLVED] Using VBA to Hide and Unhide Columns with Click of Button
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-03-2014, 03:29 PM
  4. [SOLVED] Hide And Unhide Column With One Button,,,,Once Click Hide,,,,,Again Click Unhide
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2014, 07:58 AM
  5. How to HIDE/UNHIDE Specific Sheets Using a TOGGLE Button?
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-16-2011, 02:58 AM
  6. Hide/unhide button based on data validations
    By Jazzy Max in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-08-2009, 10:00 PM
  7. [SOLVED] [SOLVED] create button that can hide/unhide sheets and hyperlink...
    By Helen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-16-2005, 12:10 AM

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