+ Reply to Thread
Results 1 to 5 of 5

VBA Code to Unhide multiple WorkSheets

Hybrid View

craig159753 VBA Code to Unhide multiple... 05-06-2015, 06:22 AM
Rioran Re: VBA Code to Unhide... 05-06-2015, 06:56 AM
craig159753 Re: VBA Code to Unhide... 05-06-2015, 08:11 AM
davesexcel Re: VBA Code to Unhide... 05-07-2015, 05:23 AM
davesexcel Re: VBA Code to Unhide... 05-06-2015, 07:16 AM
  1. #1
    Registered User
    Join Date
    05-06-2015
    Location
    Wales
    MS-Off Ver
    2010
    Posts
    13

    VBA Code to Unhide multiple WorkSheets

    So I have 5 sheets, call them "Title Page", "Page 1", "Page 2", "Page 3", "Page 4", etc.

    On the first sheet ("Title Page") I have a list of pages used in column A. This column is populated using a drop down menu.

    What i have so far is this, when someone opens the spreadsheet they will only see the "Title Page" sheet, the other sheets are hidden, which is what i want.

    On the "Title Page" in column A, the user will then select the pages they want like so

    __A__
    Page 1
    Page 3
    Page 4

    i.e. I do not want sheet "Page 2".

    I then want a VBA macro to look at the values here and unhide the pages listed. Is this possible?
    I am a total novice at VBA scripts, I know how to open the VBA section (Alt + F11 and insert a module) that is about it. Any help would be amazing!

  2. #2
    Forum Contributor
    Join Date
    09-26-2014
    Location
    Moscow, Russia
    MS-Off Ver
    MSE 10, MSE 13
    Posts
    179

    Re: VBA Code to Unhide multiple WorkSheets

    Good time of day, craig!

    You may use something like that. Test button attached.

    Sub Operate_Sheets()
        Call Hide_Them
        Call Reveal_Them
    End Sub
    
    Private Sub Hide_Them()
        Dim i&
        i = 2
        Do While Cells(i, 1).Value <> ""
            ThisWorkbook.Worksheets(Cells(i, 1).Value).Visible = False
            i = i + 1
        Loop
    End Sub
    
    Private Sub Reveal_Them()
        Dim i&
        i = 2
        Do While Cells(i, 3).Value <> ""
            ThisWorkbook.Worksheets(Cells(i, 3).Value).Visible = True
            i = i + 1
        Loop
    End Sub
    Attached Files Attached Files
    Best wishes and have a nice day!

  3. #3
    Registered User
    Join Date
    05-06-2015
    Location
    Wales
    MS-Off Ver
    2010
    Posts
    13

    Re: VBA Code to Unhide multiple WorkSheets

    This is perfect, i havent tested it yet, but looking at your example, looks really good. One question how do i add a button or assign this macro to Cntrl + Shift + D ?

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: VBA Code to Unhide multiple WorkSheets

    Quote Originally Posted by craig159753 View Post
    This is perfect, i havent tested it yet, but looking at your example, looks really good. One question how do i add a button or assign this macro to Cntrl + Shift + D ?
    It's a Worksheet_SelectionChange event, you don't assign it to anything, it runs when you select the cell.

  5. #5
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: VBA Code to Unhide multiple WorkSheets

    In a regular module use this code to hide your sheets.


    Sub HideSH()
        Dim sh As Worksheet
        For Each sh In Sheets
            If sh.Name <> "Title Page" Then
                sh.Visible = xlSheetHidden
            End If
        Next sh
    End Sub
    In the worksheet Module use this. Select the sheets names in column a to unhide them in the attached example.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Count > 1 Then Exit Sub
        If Target.Column <> 1 Then Exit Sub
        Dim sh As Worksheet
        Set sh = Sheets(Target.Value)
        Application.ScreenUpdating = 0
        sh.Visible = xlSheetVisible
    
    End Sub
    Worksheet Module
    RightClick.jpg
    Attached Files Attached Files

+ 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. Hide and unhide a range of rows in multiple worksheets
    By mrichard in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-28-2015, 05:43 PM
  2. Help with VBA Code (Hide/Unhide Worksheets)
    By maryren in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-21-2014, 12:43 PM
  3. Hide or Unhide Multiple Worksheets in a selected workbook
    By nchavan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2013, 10:11 AM
  4. how to unhide multiple worksheets at the same time?
    By hemapackiriswamy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2012, 01:47 PM
  5. How can I unhide columns on multiple worksheets in same workbook?
    By Carey N. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-15-2006, 11:15 PM

Tags for this Thread

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