Hide multiple sheets at one time with vba

Anonymous
2016-06-15T17:07:22+00:00

I would like to hide specific sheets while using an if then statement when two other sheets are already hidden.

Here is what I have:

If Sheets("A").visible=False And Sheets("B").visible=False Then Sheets("C").visible=False

This will hide sheet "C" but I also want to hide sheets D, and F.

I have tried - ...Then Sheets("C,D,F").visible=False ...but I get an error

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2016-06-15T17:36:37+00:00

    You can use

    Sheets(Array("C", "D", "F")).Visible = xlSheetHidden

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Anonymous
    2016-06-15T17:33:35+00:00

    Hi John,

    I would like to hide specific sheets while using an if then statement when two other sheets are already hidden.

    Here is what I have:

    If Sheets("A").visible=False And Sheets("B").visible=False Then Sheets("C").visible=False

    This will hide sheet "C" but I also want to hide sheets D, and F.

    I have tried - ...Then Sheets("C,D,F").visible=False ...but I get an error

    Try:

         Sheets(Array("C", "D")).Visible = xlSheetHidden

    ===

    Regards,

    Norman

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-06-15T18:39:06+00:00

    Hi John,

    I would like to hide specific sheets while using an if then statement when two other sheets are already hidden.

    Here is what I have:

    If Sheets("A").visible=False And Sheets("B").visible=False Then Sheets("C").visible=False

    This will hide sheet "C" but I also want to hide sheets D, and F.

    I have tried - ...Then Sheets("C,D,F").visible=False ...but I get an error

    Try:

         Sheets(Array("C", "D")).Visible = xlSheetHidden

    ===

    Regards,

    Norman

    Thanks, That solved my problem

    0 comments No comments
  2. Anonymous
    2016-06-15T19:52:50+00:00

    Hi John,

    Thanks, That solved my problem

    Thank you for your kind feedback and I am glad that you have resolved the problem.

    In order to close this thread, and to assist others who may search the forum archives for a solution to a similar problem, I would ask you kindly to mark the responses from Hans and myself as Answer.

    ===

    Regards,

    Norman

    0 comments No comments