1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

    Yours,
    Chandoo
  2. Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  3. When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Hide multiple sheets

Discussion in 'VBA Macros' started by Sameer.k21, Feb 11, 2019.

  1. Sameer.k21

    Sameer.k21 Member

    Messages:
    104
    Please help me correct this

    Code (vb):

        Sub VeryHiddenSheet()
             ThisWorkbook.Sheets("Sheet1", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9").Visible = xlVeryHidden
        End Sub
     
  2. YasserKhalil

    YasserKhalil Well-Known Member

    Messages:
    1,016
    Try this code
    Code (vb):
    Sub VeryHiddenSheet()
        Dim e
       
        For Each e In Array("Sheet1", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9")
            ThisWorkbook.Sheets(e).Visible = xlVeryHidden
        Next e
    End Sub
     
    Sameer.k21 and Thomas Kuriakose like this.
  3. Sameer.k21

    Sameer.k21 Member

    Messages:
    104
    Thank you, However - I get error message it says - Subscription out of range
  4. YasserKhalil

    YasserKhalil Well-Known Member

    Messages:
    1,016
    Make sure that the worksheets are there in your file
  5. Sameer.k21

    Sameer.k21 Member

    Messages:
    104
    Code (vb):
        Sub VeryHiddenSheet1()
            Sheet1.Visible = xlSheetVeryHidden
            Sheet5.Visible = xlSheetVeryHidden
            Sheet6.Visible = xlSheetVeryHidden
            Sheet7.Visible = xlSheetVeryHidden
            Sheet8.Visible = xlSheetVeryHidden
            Sheet9.Visible = xlSheetVeryHidden
            Sheet2.Activate
        End Sub
    this works
  6. YasserKhalil

    YasserKhalil Well-Known Member

    Messages:
    1,016
    These are the sheet VBE names not the sheet names .. Make sure of those names in the workbook tabs
  7. Sameer.k21

    Sameer.k21 Member

    Messages:
    104
    my bad, this is awesome :)
  8. YasserKhalil

    YasserKhalil Well-Known Member

    Messages:
    1,016
    No problem at all
    You can use the worksheet code names in that way
    Code (vb):
    Sub VeryHiddenSheet()
        Dim e
       
        For Each e In Array(Sheet1, Sheet5, Sheet6, Sheet7, Sheet8, Sheet9)
            e.Visible = xlVeryHidden
        Next e
    End Sub
  9. Sameer.k21

    Sameer.k21 Member

    Messages:
    104
    oh this seems more easy than sheet names. Thank you again :)
    YasserKhalil likes this.
  10. YasserKhalil

    YasserKhalil Well-Known Member

    Messages:
    1,016
    You're welcome. Glad I can offer some help

Share This Page