Excel vba worksheet hidden

Return to VBA Code Examples

In this Article

  • Hide Sheet in VBA
  • Unhide Sheet
  • Very Hidden Sheets
    • Unhide Very Hidden Sheets
  • Hide / Unhide Sheets in the VBA Editor
  • Hide All Worksheet Tabs
  • Hide / Unhide Sheets in Protected Workbook
  • Unhide All Sheets
  • VBA Coding Made Easy

This tutorial will teach you how to hide and unhide Worksheets with VBA.

Hide Sheet in VBA

To hide a Sheet in VBA, use the worksheet Visible property.

Either set the Visible property to FALSE:

Worksheets("Sheet1").visible = False

or set the Visible property to xlSheetHidden:

Worksheets("Sheet1").visible = xlSheetHidden

This is the same as if the user right-clicked the worksheet tab and selected “hide”.

vba hide sheet

Unhide Sheet

To unhide a Sheet in VBA, use the worksheet Visible property:

Worksheets("Sheet1").Visible = True

or

Worksheets("Sheet1").Visible = xlSheetVisible

Hidden Sheets can be seen by right-clicking in the Worksheet tab area:

vba unhide sheet

Very Hidden Sheets

The Sheet Visible property has a third option: xlSheetVeryHidden:

Worksheets("Sheet1").Visible = xlSheetVeryHidden

Very hidden Sheets are hidden when right-clicking in the Worksheet tab area:

vba very hidden sheet

This code will prevent the spreadsheet user from seeing the Worksheet tab at the bottom of the screen. It also hides the Worksheet from the user when they right-click the tabs at the bottom. The only way to see that the Worksheet exists (or unhide the Worksheet) is by opening the Visual Basic Editor.

Unhide Very Hidden Sheets

Very hidden Worksheets are made visible just like regular hidden Worksheets:

Worksheets("Sheet1").Visible = True

or

Worksheets("Sheet1").Visible = xlSheetVisible

Hide / Unhide Sheets in the VBA Editor

You can also toggle the Worksheet Visible property within the VBA Editor:

vba visible property

Hide All Worksheet Tabs

You might also want to hide the Worksheet Tab area altogether to prevent the user from navigating to different worksheets. Learn more about hiding worksheet tabs.

Hide / Unhide Sheets in Protected Workbook

Your workbook must be unprotected before you can hide or unhide worksheets.  To unprotect your workbook structure use the following code:

ActiveWorkbook.Unprotect

If your workbook structure is password-protected you must do this instead:

ThisWorkbook.Unprotect "password"

Unhide All Sheets

This procedure will unhide all worksheets in a workbook, using a For Each Loop:

Sub Unhide_All_Sheets()
    Dim ws As Worksheet
    
    ActiveWorkbook.Unprotect
    For Each ws In Worksheets
        ws.Visible = xlSheetVisible
    Next
End Sub

Notice that we first unprotect the workbook, just in case it was password protected.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!

You can use a VBA code to hide or unhide a sheet in Excel. When you right-click on the sheet tab, you can see the option to hide or unhide it, and that same thing you can do with a VBA code.

In this post, we will look at some of the ways and methods that we can use.

Let’s say you want to hide “Sheet1” from the active workbook. In that case, you need to use code like the following.

Sheets("Sheet1").Visible = False

In the above code, you have referred to Sheet1, use the visible property, and changed it to false.

Make a Sheet Very Hidden

There’s one more option that you can use to make a sheet very hidden that cannot be un-hide by the user easily.

Hide a Sheet Based on the Value from a Cell

Alright, if you want to use a cell value instead of directly using the sheet name in the code, you can refer to that cell.

Sheets(Range("A1").Value).Visible = True

This code refers to cell A1 and uses the value from it to refer to the sheet that you want to hide.

Helpful Links: Run a Macro – Macro Recorder – Visual Basic Editor – Personal Macro Workbook

Check Sheet Before Hiding

You can also use a small code like the following to check the sheet that you want to hide exits or not.

Sub vba_hide_sheet()

Dim sht As Worksheet

For Each sht In ThisWorkbook.Worksheets

    If sht.Name = "Sheet1" Then

        sht.Visible = False
        Exit Sub

    End If

Next sht

MsgBox "Sheet not found", vbCritical, "Error"

End Sub

The above code uses the FOR EACH LOOP + IF STATEMENT to loop through each sheet in the workbook. And check for the sheet that you want to hide.

Hide All the Sheets (Except ActiveSheet)

Now there one thing that you need to understand you can’t hide all the sheets. There must be one sheet visible all the time.

Sub vba_hide_sheet()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Sheets

    If ActiveSheet.Name <> ws.Name Then

        ws.Visible = False

    End If

Next ws

End Sub

The above code loops through all the sheets of the workbook, then match each sheet’s name with the active sheet’s name and hide it if it doesn’t match.

VBA Code to Unhide a Sheet

To unhide a sheet, you need to change the visible property to TRUE.

Sheets("Sheet1").Visible = False

If the sheet that you want to unhide it already visible, this code won’t show any error. But if that sheet doesn’t exist, then you’ll get a Run-time error ‘9’.

Use VBA to Unhide All the Hidden Sheets

Imagine you have more than one hidden sheet in a workbook, and if you want to hide them manually, you need to do this one by one.

But here’s the code does this in one go.

Sub vba_unhide_sheet()

Dim ws As Worksheet

For Each ws In ThisWorkbook.Sheets

    If ws.Visible = False Then

        ws.Visible = True

    End If

Next ws

End Sub

It loops through each sheet and un-hides it.

More Tutorials on VBA Worksheets

  • Back to VBA Worksheet / VBA Tutorial
Skip to content

Hide UnHide Worksheets in Excel VBA

  • Hide Unhide Worksheet Examples

VBA hide unhide worksheets example macro macro helps when we have many worksheets in a workbook and you want to show only specific worksheets to the user. You can hide unhide worksheets using Excel VBA. For Example you may be developing a tracker for different departments in an organization. Like HR, Admin, Finance, etc…, all of these may have same knind of data but the data (numbers) may vary from one department to another.
While sending the workbook to a specific department, you need to show the worksheets related to that particular department. And have hide all other worksheets, it may be confidential or not useful to that department.

VBA hide unhide worksheets – Solution

We can use Visible=FALSE to Hide a Worksheet, Visible=TRUE to UnHide a Worksheet

Hide UnHide Worksheets in Excel VBA – An Example to Hide the Worksheets

The following example will show you how to hide and unhide the worksheet using Excel VBA.

Code:
Sub sbHideASheet()

Sheet2.Visible = False
'OR You can mention the Sheet name
Sheets("Sheet2").Visible = True

End Sub
Observations:

When you hide by setting the Visible property is FALSE, it will be available for user to Unhide the Worksheets. User can right click on the Sheet tabs and Unhide the Worksheets as shown below.

Hide Unhide Worksheet Examples 1

Hide Unhide Worksheet Examples

How Hide the Worksheets, so that user can not unhide the Worksheets?:

Yes, we can hide the worksheets completely by Changing the visual property. You can set the visual property to hide the worksheets, so that user can not unhide it by right click on the Sheets Tabs. You can see the different options of hiding and unhiding the sheets in the following screen-shot.

Hide Unhide Worksheet Examples 3

Code:
Sub sbHideASheet()

Sheet2.Visible = 2 'to very hide the worksheet
'OR You can mention the Sheet name
Sheets("Sheet2").Visible = True

End Sub

Once you are done with this, you can protect the VBA project by setting the password to open it. So that user can not code it to open the Worksheets.

Advanced Hide Options

When we hide worksheets using, still user can right click on tabs and un-hide the worksheets. For example, following example will hide the worksheet and user can un hide the sheets on right click on sheet tabs:

Sub sbHideSheet()
Sheets("SheetName").Visible = False
'OR
Sheets("SheetName").Visible = xlSheetHidden
End Sub

What if you do not want to permit users to un-hide worksheet, you can set the Visible property of worksheet to xlSheetVeryHidden and lock the VBA code. so that user can not un-hide the worksheet. The below example will hide the sheet and user can not see it in un hide worksheet dialog list.

Sub sbVeryHiddenSheet()
Sheets("SheetName").Visible = xlSheetVeryHidden
End Sub

Hide Unhide sheets based on Condition (Selection Change) And Button Click

The below example file helps you to understand how to hide or unhide the sheets based on a codition (Range/Selection change), I have also shown another approach using simple buttons.
VBA to hide unhide sheets based on conditions Selection change

Download the Example VBA file here and explore your self.
https://analysistabs.com/hideunhide-sheets-based-on-condition/

Effortlessly Manage Your Projects and Resources
120+ Professional Project Management Templates!

A Powerful & Multi-purpose Templates for project management. Now seamlessly manage your projects, tasks, meetings, presentations, teams, customers, stakeholders and time. This page describes all the amazing new features and options that come with our premium templates.

Save Up to 85% LIMITED TIME OFFER
Excel VBA Project Management Templates
All-in-One Pack
120+ Project Management Templates
Essential Pack
50+ Project Management Templates

Excel Pack
50+ Excel PM Templates

PowerPoint Pack
50+ Excel PM Templates

MS Word Pack
25+ Word PM Templates

Ultimate Project Management Template

Ultimate Resource Management Template

Project Portfolio Management Templates

Related Posts

    • VBA hide unhide worksheets – Solution
    • Hide UnHide Worksheets in Excel VBA – An Example to Hide the Worksheets
    • Advanced Hide Options
    • Hide Unhide sheets based on Condition (Selection Change) And Button Click

VBA Reference

Effortlessly
Manage Your Projects

120+ Project Management Templates

Seamlessly manage your projects with our powerful & multi-purpose templates for project management.

120+ PM Templates Includes:

37 Comments

  1. Ramesh
    March 24, 2015 at 7:45 PM — Reply

    I would like to use the both Hide and Unhide in one VBA, as I would like to hide the active/current sheet and unhide the specified sheet.

    please advise me how to code it…

    thanks a Tons in advance:-)

  2. PNRao
    March 24, 2015 at 9:56 PM — Reply

    Hi Ramesh,

    How do you want to hide or unhide the sheets. The below code will unhide Sheet2 AND hide Sheet1.

    Sub sbHidAndUnHideSheets()
        Sheets("Sheet2").Visible = True 'To unhide the Sheet2
        Sheets("Sheet1").Visible = False 'To hide the Sheet1    
    End Sub
    

    Hope this helps-Thanks-PNRao!

  3. Ramesh
    March 29, 2015 at 12:12 PM — Reply

    Thanks Rao sir,

    Its perfectly working, upon the un hiding sheet 2 how to make a sheet 2 as active sheet as I have multiple sheets, currently once the code run the display sheet showing something like sheet 4/5.

    kindly advise.

  4. Ramesh
    March 29, 2015 at 12:16 PM — Reply

    Furthermore,the hiding option should be “xlSheetVeryHidden”, kindly assist me. :-)

  5. Nicola
    March 30, 2015 at 4:54 PM — Reply

    How can you hide or unhide certain tabs for specific users? I was attempting the following code but the uname2 section has a syntax error.

    UserNameWindows() As String
    unamewindows = Environ(“Username”)
    Uname2 = StrConv(unamewindows, vbUpperCase)

    If Uname2 = “PERSON1” _
    Or Uname2 = “PERSON2” _
    Or Uname2 = “PERSON3” _

    Sheets(“Copy Data”).Visible = True

    End If

  6. PNRao
    April 1, 2015 at 7:21 PM — Reply

    You use the Activate method of worksheet:

    Sheets("SheetName").Activate
    

    Thanks-PNRao!

  7. PNRao
    April 1, 2015 at 7:24 PM — Reply

    You use the Activate method of worksheet:

    Sheets("SheetName").Visible = xlSheetVeryHidden
    

    Thanks-PNRao!

  8. PNRao
    April 1, 2015 at 7:28 PM — Reply

    You are missing the ‘Then’ keyword: Please use the below code

    Sub SbShow_Or_Hide_The_Tabs_To_Specific_Users()
        Dim UserNameWindows As String
        unamewindows = Environ("Username")
        Uname2 = StrConv(unamewindows, vbUpperCase)
        If Uname2 = "PERSON1" _
            Or Uname2 = "PERSON2" _
            Or Uname2 = "PERSON3" Then
            Sheets("Copy Data").Visible = True
        End If
    End Sub
    

    Thanks-PNRao!

  9. yuko
    July 2, 2015 at 9:58 AM — Reply

    Hi.
    I’m used this code:
    Sub sbHidAndUnHideSheets()
    Sheets(“Sheet1”).Visible = False ‘ To hide the Sheet1
    Sheets(“Sheet2”).Visible = True ‘To unhide the Sheet2
    End Sub

    Edit for my work:
    Sub sbHidAndUnHideSheets()
    Sheets(“Khuon”).Visible = False
    Sheets(“Duc”).Visible = True
    End Sub

    Shortcut key: Ctrl + H for use this. but it isn’t work. Error with yellow highlight: Sheets(“Khuon”).Visible = False

    Pls help me!

  10. PNRao
    July 2, 2015 at 10:16 AM — Reply

    Hi Yuko,

    Use the below code when you have only two sheets in your workbook. We can not hide all worksheets in a workbook, at least on worksheet should be visible. Just swap the statements to avoid the issue:

    Sub sbHidAndUnHideSheets1()
        Sheets("Sheet2").Visible = True 'To unhide the Sheet2
        Sheets("Sheet1").Visible = False 'To hide the Sheet1
    End Sub
    
    'Edit for my work:
    Sub sbHidAndUnHideSheets()
        Sheets("Duc").Visible = True
        Sheets("Khuon").Visible = False
    End Sub
    

    Thanks-PNRao!

  11. yuko
    July 2, 2015 at 2:17 PM — Reply

    Hi PNRao!
    Thank you so much!

  12. PNRao
    July 2, 2015 at 4:50 PM — Reply
  13. David
    July 18, 2015 at 1:50 AM — Reply

    Hi,
    This has been really useful, want can I do if I want to have a worksheet with a dropdown menu where I could select the tab I want to be unhidden, and the rest of them hidden?

    Thanks

    David

  14. PNRao
    July 18, 2015 at 2:09 PM — Reply

    Hi David,
    Yes, this is possible. You can fill the drop down while opening the workbook

    Place a Combo Box in the required worksheet (Example: in Sheet1). And place the below code in ThisWorkbook Code module:

    Private Sub Workbook_Open()
        Sheets("Sheet1").ComboBox1.Clear
        For Each sht In ThisWorkbook.Sheets
            Sheets("Sheet1").ComboBox1.AddItem sht.Name
        Next
    End Sub
    

    And place the below code in the Worksheet module (i.e: Sheet1 Code module):

    Private Sub ComboBox1_Change()
    If Not ComboBox1.ListIndex >= 0 Then Exit Sub
    
    'Unhide/show the required sheet
        Sheets(ComboBox1.Value).Visible = True
    
    'hide all other sheets
        For Each sht In ThisWorkbook.Sheets
            If sht.Name <> ComboBox1.Value Then sht.Visible = False
        Next
    
    'You may want Sheet1 should be visible always
        Sheets("Sheet1").Visible = True
        Sheets("Sheet1").Activate
    End Sub
    

    This will make you to select required worksheet visible and hide all other sheets.

    Thanks-PNRao!

  15. David
    July 21, 2015 at 12:53 AM — Reply

    Thanks PNRao!

    I have ben tying with this but can’t get it wo work for me… I am not using a private sub so I can just run it anytime with a specific command.
    The message I am getting is that there is an Object Required. My ComboBox y also named ComboBox1.
    Also if my sheets are already named, do I need the first part of code you sent?

    Thanks a lot!

  16. PNRao
    July 23, 2015 at 1:29 PM — Reply

    Hi David,
    Yes, you need to both the codes.

    The first code will goes to ThisWorkbook Module:(go to Project explorer and and double click on the ThisWorkbook class module and paste the code)

    And the second code goes to your worksheet Module:(go to Project explorer and and double click on the required Sheet class module and paste the code)

    Hope this helps!
    Thanks-PNRao!

  17. Dan Bailey
    August 24, 2015 at 8:39 PM — Reply

    I working on an application with 6 sheets that interact with each other via code. I do not want the users to be able to see the sheet tabs BUT, I need to be able to interact with them. I’m using Excel 2013 (xlsm file) and went into the File- Options-Advanced and deselected “Sheet Tabs visible”. The tabs are hidden and I can still access the sheet. However, after I save and close the workbook and then reopen it the sheet tabs are there again. I am at a lose as to why the sheet tab return. Is there some VBA code that can duplicate what the Options-Advance setting should keep in the workbook but does not.? I would be so grateful if someone could help me out on this one.

  18. Dan Bailey
    August 24, 2015 at 9:34 PM — Reply

    I have discovered the problem. The file I need to hide the “Sheet Tabs” only is a “XLSM” micro enabled workbook. I opened a “XLSX” file and tested the Options – Advanced and deselected “Sheet Tabs visible” and they went away. After I save and reopened the file the Tabs were still hidden. Is there any way to hide the Tabs only in a “XLSM” workbook?? Or is there anyway I can use a “XLSX” workbook and write VBA code in it. Thanks. Dan

  19. PNRao
    August 25, 2015 at 12:30 AM — Reply

    Hi,
    I have updated the post, please see the last example to make worksheets Very Hidden.
    Thanks-PNRao!

  20. Priya
    October 28, 2015 at 3:01 PM — Reply

    Hi,

    I have index sheet from which i want to access other sheets.. I have different sheets for expenses, payroll, taxes and so on and i have given hyperlink to all these sheets from the index page.
    I want to hide all the sheets except the index..and from here when the user clicks on a desired link.. it should take the user to the specified sheet. Even it is hidden. Please help

    Priya

  21. samola
    November 6, 2015 at 2:36 AM — Reply

    Hello,

    I am trying to hide all sheets except two, below is what I have to hide only one sheet. I need to expand it so that I can keep “approval” visible.

    Dim wk As Worksheet
    For Each wk In Worksheets
    If Not wk.Name = “AdviceForm” Then wk.Visible = xlSheetHidden

    Next

    End Sub

    Thanks for your assistance in this matter.

    Regards,
    Samola

  22. Deepu
    November 12, 2015 at 10:59 AM — Reply

    Hi,

    I would like to hide all sheet except the summary tab, how to do it? Please advice. Thanks

    Deepu

  23. PNRao
    November 16, 2015 at 4:08 PM — Reply

    Here is code to hide all sheets except one summary sheet:

    Sub sbHideAllExceptSummary()
        Sheets("Summary").Visible = True
        For Each sht In ActiveWorkbook.Sheets
            If sht.Name <> "Summary" Then sht.Visible = False
        Next
    End Sub
    

    Thanks-PNRao!

  24. Sammie
    December 6, 2015 at 3:46 PM — Reply

    Hi,
    Please I’m working on a daily report, how can I create a button on that will lead the user to another sheet were they can fill in details? Please help really urgent.
    Thank you.

  25. SGirard
    February 5, 2016 at 1:36 AM — Reply

    Hi PNRao,

    I am using multiple sheet that all depends on the Data entry one. Based on one selection on the Data entry, is it possible to hide or unhide automatically specific sheet?

    I have 3 different type of Implementation. On the Data entry, i need to select the current implementation. It will modify a list that will control the content of different Sheet. I would like to hide the useless sheet and show only the ones that belong to this implementation.

    kind of:

    If ‘Client Information’B17=”Migration”
    Then Sheets(“Discovery Call”).Visible = True
    Sheets(‘Best Practice’) Visible=False

    Can you help me?

  26. PNRao
    February 5, 2016 at 8:30 PM — Reply

    Hi Giridar,

    You can achieve this with many approaches, here are the two best methods:

    Method 1: Using Worksheet Events to hide unhide sheets

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("B17").Address Then
        If Range("B17") = "Migration" Then
            sbButtonSet1
        ElseIf Range("B17") = "Other Set2" Then
            sbButtonSet2
        ElseIf Range("B17") = "Other Set3" Then
            sbButtonSet3
        Else
            sbButtonHideAll
        End If
    End If
    End Sub
    

    Method 2:This is another approach to hide unhide the sheets by using Buttons (recommended)

    Sub sbButtonSet1()
    Call ShowOnlySheets("Set1a,Set1b")
    End Sub
    Sub sbButtonSet2()
    Call ShowOnlySheets("Set2a,Set2b")
    End Sub
    Sub sbButtonSet3()
    Call ShowOnlySheets("Set3a,Set3b")
    End Sub
    
    Sub sbButtonHideAll()
    Call ShowOnlySheets(")
    End Sub
    
    Sub ShowOnlySheets(ByVal strSheets As String)
    'strSheets is parameter to specify the rqeuired sheet names (comma separated)
    
    'Hide all sheets except the main sheet
    For Each sht In ActiveWorkbook.Sheets
    If sht.Name <> "Main" Then sht.Visible = False
    Next
    
    'Unhide the required sheets
    For i = 0 To UBound(Split(strSheets, ","))
    Sheets(Split(strSheets, ",")(i)).Visible = True
    Next
    
    End Sub
    

    I recommend the second method as it will be user friendly, also avoids the unnecessary event calls.

    Please find the example file here:
    http://analysistabs.com/hideunhide-sheets-based-on-condition/

    Thanks-PNRao!

  27. Venkat
    March 3, 2016 at 3:12 PM — Reply

    Hi
    I have created navigation in home page. But the thing I want is to hide the sheet names which are shown below. But it should be accessed when the buttons are clicked.

    Simply to say “Sheets should be hidden, but should be accessible”

    Could you please help me in this issue.

    Thanks in advance.

  28. Jorge
    April 20, 2016 at 8:04 PM — Reply

    Hi,
    In regards to hiding or unhiding- I know I can do that with a sheet, but can I hide a condition inside a sheet?
    This is the macro that I’m using and it pops “Run-time error ‘438’: Object doesn’t support this property or method”
    Sub TransferStuff()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Range(“M1”, Range(“M” & Rows.Count).End(xlUp)).AutoFilter 1, ”
    Range(“A2”, Range(“L” & Rows.Count).End(xlUp)).Copy Sheet2.Range(“A” & Rows.Count).End(3)(2)
    Range(“A2”, Range(“L” & Rows.Count).End(xlUp)).Visible = False
    [M1].AutoFilter

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Sheet2.Select

    End Sub

  29. Colin
    August 26, 2016 at 5:40 PM — Reply

    Hi,

    I keep getting an error at the point below. I’m quite new to this so still learning.

    For i = 0 To UBound(Split(strSheets, “,”))
    Sheets(Split(strSheets, “,”)(i)).Visible = True

    I’m not sure why, any help would be appreciated.

    Thanks

    C

  30. brendan
    November 23, 2016 at 4:51 PM — Reply

    Hi

    I would like to be able to create a button on a home page to open a hidden sheet which needs a password to gain entry. (either separate buttons or a drop down list)
    I have 1 sheet as the main page and 6 other sheets for each individuals personal xmas savings.

    How would i do this?

  31. Matt
    March 7, 2017 at 8:57 PM — Reply

    Hi PNRao,

    I’ve got a workbook that presently has 38 pages. I’ve included code to create a dynamic index.
    Private Sub Worksheet_Activate()
    Dim xSheet As Worksheet
    Dim xRow As Integer
    Dim calcState As Long
    Dim scrUpdateState As Long
    Application.ScreenUpdating = False
    xRow = 1
    With Me
    .Columns(1).ClearContents
    .Cells(1, 1) = “INDEX”
    .Cells(1, 1).Name = “Index”
    End With
    For Each xSheet In Application.Worksheets
    If xSheet.Name Me.Name Then
    xRow = xRow + 1
    With xSheet
    .Range(“A1”).Name = “Start_” & xSheet.Index
    .Hyperlinks.Add anchor:=.Range(“A1″), Address:=”, _
    SubAddress:=”Index”, TextToDisplay:=”Back to Index”
    End With
    Me.Hyperlinks.Add anchor:=Me.Cells(xRow, 1), Address:=”, _
    SubAddress:=”Start_” & xSheet.Index, TextToDisplay:=xSheet.Name
    End If
    Next
    Application.ScreenUpdating = True
    End Sub

    When the index is created it links back to the index page but it is deleting a line I am trying to keep. I would like to insert a row before creating the link back to the index. Also when creating the index I would like to have it auto generate a checkbox to be used to hide worksheets not needed for the project we are working on.

    I would like to use the same checkbox to hide rows on the cover sheet as well.

    If you could provide any help it would be immensely appreciated.

  32. Ali
    March 8, 2017 at 3:55 AM — Reply

    Hi

    I have 2 Sheets Sheet 1(Home) and Sheet 2(Info) .
    How can i to hide Sheet2 and create a macro in Sheet1 for unhide that ,When i go back to Sheet1 automatically Sheet2 automatically be hidden ??????????

    please help me.

  33. Jafar
    October 16, 2018 at 8:18 AM — Reply

    Hi PNRao,

    I would like to visible only link desire sheet which already hidden. How to do it? Please advice.
    Thanks/
    Jafar

  34. puneet
    December 13, 2018 at 3:22 PM — Reply

    Hi All,

    I have a workbook containing multiple i need to hide them on the basis of their name ending . Can you please help

  35. Devraj Adhikari
    June 28, 2020 at 12:33 AM — Reply

    I Have a More Than a 100 Sheets in a Worksheet if i want to hide sheets 1,5,76,99,32,45,57 Than How Can i Hide Only This Sheets

  36. PNRao
    September 6, 2020 at 9:08 PM — Reply

    Sub HideListOfSheetsWithNumber()
    sheetsToHide = “1,5,76,99,32,45,57” ‘ Sheet Numbers to Hide
    sheetsToHide = Split(sheetsToHide, “,”)

    For iCntr = 0 To UBound(sheetsToHide)
    Sheets(sheetsToHide(iCntr)).Visible = False
    Next
    End Sub

  37. Alan
    November 10, 2020 at 9:09 PM — Reply

    I leave 5 tabs unhidden and then use the Sheets(“xxx”).visible =True method to unhide the sheet(s) I need to make available. The problem is the newly visible tabs don’t appear in places I expect them, sometimes at position 6 +, sometimes in the middle of first 5. Can I designate a next position or do I have to use the .Move method to manage where they show up?

Effectively Manage Your
Projects and  Resources

With Our Professional and Premium Project Management Templates!

ANALYSISTABS.COM provides free and premium project management tools, templates and dashboards for effectively managing the projects and analyzing the data.

We’re a crew of professionals expertise in Excel VBA, Business Analysis, Project Management. We’re Sharing our map to Project success with innovative tools, templates, tutorials and tips.

Project Management
Excel VBA

Download Free Excel 2007, 2010, 2013 Add-in for Creating Innovative Dashboards, Tools for Data Mining, Analysis, Visualization. Learn VBA for MS Excel, Word, PowerPoint, Access, Outlook to develop applications for retail, insurance, banking, finance, telecom, healthcare domains.

Analysistabs Logo

Page load link

Go to Top

Hiding and Unhiding worksheets in Excel is a straightforward task.

You can hide a worksheet and the user would not see it when he/she opens the workbook. However, they can easily unhide the worksheet if they want (as we will see later in this tutorial).

But what if you don’t want them to be able to unhide the worksheet(s).

To do that, you need to take a couple of additional steps to make sure the worksheets are ‘very hidden’ (also covered later in this tutorial).

Let’s see how to hide a worksheet in Excel so that it can easily be unhidden, or can not be unhidden.

Regular Way of Hiding a Worksheet in Excel

You can use the below steps to hide a worksheet in Excel:

  • Right-click on the sheet tab that you want to hide.
  • Click on Hide.Hide a worksheet in Excel - right click and select Hide

This would instantly hide the worksheet, and you will not see it in the workbook. This setting remains intact when you save the workbook and reopen it again, or send it to some else.

PRO TIP: To hide multiple sheets at one go, hold the Control key and then select the sheet tabs (that you want to hide) one by one. Once selected, right-click on any one of the selected tabs and click on ‘Hide”. This will hide all the worksheets at one go.

While this method hides the worksheet, it’s extremely easy to unhide these worksheets as well.

Here are the steps to unhide a worksheet in Excel:

This will instantly make the sheet visible in the workbook.

Note that you can only unhide one sheet at a time. To unhide multiple sheets, you need to repeat the above steps to unhide each worksheet. Alternately, you can use a macro code to unhide all the worksheets at one go.

While this method works in most cases, it doesn’t really help if you want to hide the worksheets so that your client or colleague (or anyone with whom you share the workbook) can’t unhide and view these.

All they need to do is right-click on any of the tabs and they will see what all worksheets are hidden (and unhide these easily).

So let’s see how you can really hide a worksheet so that it can not be unhidden (at least not so easily).

Hide a Worksheet So That It Can Not be Unhidden

Here are the steps to hide a worksheet so that it can not be unhidden:

Now you will notice that the sheet is hidden.

When you right-click on any of the tabs, you will not see it in the list of hidden sheets that you can unhide.

Is this method foolproof? – NO!

This method works as a user can not see the hidden sheet in the list of sheets that he/she can unhide.

But this doesn’t mean that the sheet can’t be unhidden.

Unhide a Sheet that has been ‘Very Hidden’

Here are the steps to unhide a sheet that has been ‘Very Hidden’:

This will unhide the worksheet and it will be visible in the workbook.

Hide/Unhide Worksheets Using VBA

If you have a lot of worksheets that you need to hide/unhide, it can take up a lot of your time.

Using a simple VBA code can automate this task for you.

Hide All Worksheets Using VBA

Below is the VBA code that will hide all the worksheets except the current/active worksheet:

'This macro will hide all the worksheet except the active sheet
Sub HideAllExceptActiveSheet()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then ws.Visible = xlSheetHidden
Next ws
End Sub

The above code would hide all the worksheet except the except the active sheet. However, it will hide it so that these can be unhidden easily (note that ws.Visible property is set to xlSheetHidden).

If you want to hide the sheets so that these can not be unhidden, use the below code:

'This macro will hide all the worksheet except the active sheet
Sub HideAllExcetActiveSheet()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then ws.Visible = xlSheetVeryHidden
Next ws
End Sub

The only change we have done here is making the ws.Visible property xlSheetVeryHidden.

Unhide All Worksheets Using VBA

Below is the code that will unhide all the hidden worksheets in the workbook.

'This code will unhide all sheets in the workbook
Sub UnhideAllWoksheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
End Sub

Using this code, we simply go through each worksheet one by one and make the ws.Visible property equal to xlSheetVisible.

Where to put the code?

Below are the steps to place the code in the VB Editor:

Now you can assign the macro to a shape or run it from the Developer tab. You can read more about different ways to run a macro in Excel here.

Note that you don’t need to insert a new module for each code. You can have one single module and have multiple VBA macro codes in it.

You May Also Like the Following Excel Tutorials:

  • Unhide Columns in Excel (A Simple Step-by-step Guide)
  • How to Unhide Sheets in Excel (All In One Go)
  • How to Create and Use an Excel Add-in.
  • Useful Excel Macros for Beginners.
  • How to Lock Cells in Excel.
  • How to Lock Formulas in Excel.
  • Hide Zero Values in Excel
  • How to Delete All Hidden Rows and Columns in Excel
  • How to Hide or Show Formula Bar in Excel?

Содержание

  1. Скрытие листов и использование константы xlVeryHidden в макросе
  2. Аннотация
  3. Дополнительные сведения
  4. Скрытие листа с помощью команд меню
  5. Скрытие листа с помощью макроса Visual Basic
  6. Пример кода Visual Basic
  7. Hiding Sheets with VBA xlSheetHidden and xlSheetVeryHidden
  8. The VBA Tutorials Blog
  9. The Usual Boolean Property
  10. The Unhide Dialogue
  11. Hiding Sheets More Thoroughly
  12. Protecting from Prying Eyes
  13. A Note on Security
  14. User Friendly
  15. Leadership pointers, innovation, creativity, design tips and templates, effective communication and how to guides by Alesandra Blakeston
  16. Very hidden Excel Sheets
  17. Hiding / Unhiding a sheet – the basics
  18. Very hidden sheets
  19. Using vba to make a sheet very hidden / visible
  20. VBA Sheets – The Ultimate Guide
  21. Sheets Vs. Worksheets
  22. Referencing Sheets
  23. ActiveSheet
  24. Sheet Name
  25. Sheet Index Number
  26. Sheet Index Number – Last Sheet in Workbook
  27. Sheet “Code Name”
  28. VBA Coding Made Easy
  29. Referencing Sheets in Other Workbooks
  30. Activate vs. Select Sheet
  31. Activate a Sheet
  32. Select a Sheet
  33. Select Multiple Sheets
  34. Worksheet Variable
  35. Loop Through All Sheets in Workbook
  36. Worksheet Protection
  37. Workbook Protection
  38. Worksheet Protection
  39. Protect Worksheet
  40. Unprotect Worksheet
  41. Worksheet Visible Property
  42. Unhide Worksheet
  43. Hide Worksheet
  44. Very Hide Worksheet
  45. Worksheet-Level Events
  46. Worksheet Activate Event
  47. Worksheet Change Event
  48. Worksheet Cheat Sheet
  49. VBA Worksheets Cheatsheet
  50. VBA Code Examples Add-in

Аннотация

В Microsoft Excel можно скрыть листы в книге, чтобы пользователь не отображал их. В книге можно скрыть лист любого типа, но всегда должен быть виден хотя бы один лист.

Дополнительные сведения

Скрытие листа с помощью команд меню

Чтобы скрыть лист, наведите указатель мыши на пункт «Лист» в меню «Формат» и нажмите кнопку «Скрыть». Чтобы отобразить лист, наведите указатель на пункт «Лист» в меню «Формат» и нажмите кнопку «Отобразить». Выберите соответствующий лист и нажмите кнопку «ОК».

Невозможно скрыть листы модулей, так как они отображаются в редакторе Visual Basic.

Скрытие листа с помощью макроса Visual Basic

Вы также можете скрыть или отобразить лист с помощью макроса Visual Basic для приложений майкрософт. При использовании кода Visual Basic можно использовать свойство xlVeryHidden, чтобы скрыть лист и не отображать его в диалоговом окне «Отобразить». При этом единственный способ снова сделать лист видимым — создать другой макрос Visual Basic.

В макросе Visual Basic используйте свойство Visible, чтобы скрыть или отобразить лист. Для свойства Visible можно задать значение True, False или xlVeryHidden. Значения True и False имеют тот же эффект, что и при использовании команд меню «Отобразить» или «Скрыть». Аргумент xlVeryHidden скрывает лист, а также не отображает диалоговое окно «Отобразить».

Пример кода Visual Basic

Корпорация Майкрософт предоставляет примеры программирования только в целях демонстрации без явной или подразумеваемой гарантии. Данное положение включает, но не ограничивается этим, подразумеваемые гарантии товарной пригодности или соответствия отдельной задаче. Эта статья предполагает, что пользователь знаком с представленным языком программирования и средствами, используемыми для создания и отладки процедур. Инженеры службы поддержки Майкрософт могут помочь объяснить функциональные возможности конкретной процедуры, но они не будут изменять эти примеры, чтобы предоставить дополнительные функциональные возможности или процедуры создания в соответствии с конкретными требованиями. В следующих примерах показано, как использовать свойство Visible объекта Sheet.

В следующем примере показано, как использовать аргумент xlVeryHidden свойства Visible для скрытия листа:

Источник

The VBA Tutorials Blog

In keeping with our recent theme of making workbooks easier to navigate (hiding columns, deleting columns), this post will take a look at the .Visible property of sheets and its three possible values. This property lets you hide and unhide sheets with its three options: True, xlSheetHidden, and xlSheetVeryHidden.

Knowing how to hide sheets with VBA is valuable if you need to clean up the user interface or protect calculations to prevent accidental modification.

The Usual Boolean Property

You may have noticed that many VBA object properties are Booleans. This means they can only be True or False . Common Boolean properties include .Hidden for columns/rows, font properties like Font.Bold , and text properties like Cells.WrapText . These can only take Boolean values, and that intuitively makes sense. How can the Bold property of a font be any value other than True or False?

To determine whether a property is likely Boolean, you can ask the simple question “Is the object property ?” For example, “is the font bold?” or “is the column hidden?”. If the answer is naturally yes/no, then it’s most likely a Boolean property.

The [Sheet].Visible property surely fits this heuristic: is Sheet1 visible? It is natural to answer this question with a yes or no. To complicate it even more, the values True and False can certainly be assigned to the sheet object’s .Visible property. You can hide a sheet using the [Immediate window] (press Ctrl+g in the VBE to open it) by executing this code:

and Sheet1 will be hidden from view in the tabs at the bottom of the Excel window. To show it again, set the property to True:

and Sheet1 will reappear.

If you have Intellisense enabled — which I recommend for everyone, but especially those learning VBA — you might have noticed that [Sheet].Visible does not display True and False as its options, though.

The Unhide Dialogue

One reason to hide sheets is to clean up the interface so it’s easier for users to navigate. This applies to complex workbooks wherein a single sheet handles inputs and a single sheet for results suffices to satisfy user needs, while perhaps 5 sheets store useful historical data and 3 set up and perform calculations. The 8 data and processing sheets are not really necessary for the user, and it can clutter up the display or even confuse inexperienced users.

By right-clicking on the sheets group at the bottom of the Excel window, users can look at hidden sheets. That is, they can see a list of sheets whose .Visible property is set to False . They can then unhide those sheets to look at or change them.


The Unhide Dialogue, which lists hidden sheets and allows the user to re-display them

What if you want to make sheets more hidden? For example, if you want to prevent users from accidentally — or maliciously — changing formulas. To do this, we can use the third legal value for the .Visible property of sheets, xlSheetVeryHidden .

Hiding Sheets More Thoroughly

To avoid issues with curious users who may want to see what sheets are hidden, you can use VBA to obscure especially sensitive sheets from a GUI-user’s view. Instead of setting the .Visible property to False (which is the same as setting it to xlSheetHidden ), you can set it to a third value: xlSheetVeryHidden . This makes the sheet invisible not only on the tab tray but also in the Unhide Dialogue, so users can’t even unhide it that way.

Hide the sheet graphically in VBE with the Properties window (usually shortcutted via F4 while the VBE is open). Change the Visible property manually via the red box here:


The Properties Window for Sheet1 with Visible property highlighted

Or, of course, you can set the .Visible property in code:

This example uses the VBA CodeName Sheet1 to hide the sheet, but you could also spell out the sheet name, like Sheets(«Sheet1») .

The only way for a Very Hidden sheet to be unhidden is through the VBA editor. For less-skilled users, they might not even know how to enable the Developer tab, while others may not know how to use VBA. This certainly is not a secure solution against an adept attacker, but it will likely keep most coworkers and clients from unhiding and inadvertently breaking sheets.

There are shorter ways to make a sheet very hidden, though. The value xlSheetVeryHidden is the same as xlVeryHidden , just like a value False is the same as a value of xlSheetHidden , which is the same as a value of xlHidden . You can use whichever nomenclature you like!

Make powerful macros with our free VBA Developer Kit

This is actually pretty neat. If you have trouble understanding or remembering it, our free VBA Developer Kit can help. It’s loaded with VBA shortcuts to help you make your own macros like this one — we’ll send a copy, along with our Big Book of Excel VBA Macros, to your email address below.

Protecting from Prying Eyes

If you want, you can set passwords on VBA Projects through the Tools > VBAProject Properties. menu item (blue box below). On the Protection tab, add your password and check the Lock project for viewing checkbox (red box). When you close the Excel file and re-open it, the project will be collapsed in the Project Explorer window and no one will be able to view the object properties or code modules without entering the password.


Password Protection Window with VBAProject Properties

A Note on Security

If you’re worried about users maliciously changing the sheets or stealing intellectual property, using a password to protect the project is not very secure. If you have highly sensitive data on hidden sheets, I’d recommend another approach. If you are simply comparing inputs, at least store hashed data instead of plaintext. If you need to operate on the data, consider a database connection that Excel can query every time it needs to operate on the data.

For most office applications, a very high level of security is not necessary, and password protecting your VBA project will suffice. If you need more security on your spreadsheets, I typically recommend Unviewable+. It’s not invincible, but it does a good job protecting against the most common hacking techniques.

Hopefully this tutorial taught you how to hide, unhide, and make sheets very hidden using VBA. It may have surprised you that .Visible is not a Boolean property, since most properties are. With a Very Hidden sheet, you can stop some curious users from seeing sensitive information or accidentally changing formulas on sheets for calculations.

If you want, you can even password protect your VBA projects now, but bear in mind that a weak password may be easily broken. And if you have to protect data from truly malicious actors, I would recommend another approach. The average curious office user, though, will likely be thwarted by password protection and Very Hidden sheets.

To learn more VBA tips like this one, subscribe using the form below.

Ready to do more with VBA?
We put together a giant PDF with over 300 pre-built macros and we want you to have it for free. Enter your email address below and we’ll send you a copy along with our VBA Developer Kit, loaded with VBA tips, tricks and shortcuts.

Before we go, I want to let you know we designed a suite of VBA Cheat Sheets to make it easier for you to write better macros. We included over 200 tips and 140 macro examples so they have everything you need to know to become a better VBA programmer.

This article was written by Cory Sarver, a contributing writer for The VBA Tutorials Blog. Visit him on LinkedIn and his personal page.

Источник

User Friendly

Leadership pointers, innovation, creativity, design tips and templates, effective communication and how to guides by Alesandra Blakeston

Have you ever been frustrated because you cannot find the sheet an Excel calculation is referring to? It’s not a variable listed in the name manager, it’s not hidden in the normal manner, so where on earth could it be! I give you Excel’s “very hidden” worksheets. Sneaky, no?

In actual fact a worksheet can be visible, hidden or very hidden. Before we look at very hidden sheets, though, let’s go over the basics.

Hiding / Unhiding a sheet – the basics

Hiding a sheet from view is actually very easy. Simply right click on the tab and choose the “Hide” option.

To make the sheet visible again, click on any of the remaining tabs and click on “Unhide…” Of course, if no tabs are hidden this option will be greyed out (unavailable). It will also appear greyed out if you have set a sheet / sheets to be very hidden, making it more difficult for a user to access or edit important calculations for example on this very hidden sheet.

To make a worksheet very hidden or to make it visible again (in Excel 2010), you will need to access the Visual Basic Editor via the developers tab on the ribbon. First if you haven’t got the developer tab visible on your ribbon, you will need to make it visible. Step 1 of this previous article shows you how to do this.

Once the developer tab is visible, click on the “Visual Basic” button.

This will open the Visual Basic Editor.

If the “Properties window” is not already open, click on “View” > “Properties Window” or press the function key F4.

This will open up the window as shown below:

In the project window above the properties window, click on the sheet you want to make “Very Hidden”. In my example, I have chosen sheet 2 as shown in the picture above. The very last property of the sheet, is the visible property. There are three possible options. Click once on the value of the Visible property to see the drop down arrow to access the different options.

To make the sheet “Very Hidden”, choose the last option “2 – xlSheetVeryHidden”. To make a very hidden sheet visible again, choose “-1 – xlSheetVisible”. The second option “0 – xlSheetHidden” simply hides the sheet. You can make it visible again by right clicking on any of the excel tabs and choosing “Unhide…” as shown earlier.

Remember: when a sheet is very hidden you cannot see it except in the Visual Basic Editor. A user of the sheet cannot right click a tab and see it listed among the other sheets that are simply hidden.

If you are familiar with vba, you can of course use the following code to change the Visible property of a sheet instead.

To make a sheet very hidden: Sheets(«SheetName«).Visible = xlVeryHidden»

To make a sheet hidden: Sheets(«SheetName«).Visible = xlHidden»

To make a sheet visible: Sheets(«SheetName«).Visible = True»

Источник

VBA Sheets – The Ultimate Guide

In this Article

This is the ultimate guide to working with Excel Sheets / Worksheets in VBA.

At the bottom of this guide, we’ve created a cheat sheet of common commands for working with sheets.

Sheets Vs. Worksheets

There are two ways to reference Sheets using VBA. The first is with the Sheets object:

The other is with the Worksheets object:

99% of the time, these two objects are identical. In fact, if you’ve searched online for VBA code examples, you’ve probably seen both objects used. Here is the difference:

The Sheets Collection contains Worksheets AND Chart Sheets.

So use Sheets if you want to include regular Worksheets AND Chart Sheets. Use Worksheets if you want to exclude Chart Sheets. For the rest of this guide we will use Sheets and Worksheets interchangeably.

Referencing Sheets

There are several different ways to reference Sheets:

  • ActiveSheet
  • Sheet Tab Name
  • Sheet Index Number
  • Sheet Code Name

ActiveSheet

The ActiveSheet is the Sheet that’s currently active. In other words, if you paused your code and looked at Excel, it’s the sheet that is visible. The below code example will display a MessageBox with the ActiveSheet name.

Sheet Name

You are probably most familiar with referencing Sheets by their Tab Name:

This is the sheet name that’s visible to Excel users. Enter it into the sheets object, as a string of text, surrounded by quotations.

Sheet Index Number

The Sheet Index number is the sheet position in the workbook. 1 is the first sheet. 2 is the second sheet etc.:

Sheet Index Number – Last Sheet in Workbook

To reference the last Sheet in the workbook, use Sheets.Count to get the last Index Number and activate that sheet:

Sheet “Code Name”

The Sheet Code Name is it’s Object name in VBA:

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro — A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

Referencing Sheets in Other Workbooks

It’s also easy to reference Sheets in other Workbooks. To do so, you need to use the Workbooks Object:

Important: The Workbook must be open before you can reference its Sheets.

Activate vs. Select Sheet

In another article we discuss everything about activating and selecting sheets. The short version is this:

When you Activate a Sheet it becomes the ActiveSheet. This is the sheet you would see if you looked at your Excel program. Only one sheet may be activate at a time.

Activate a Sheet

When you select a Sheet, it also becomes the ActiveSheet. However, you can select multiple sheets at once. When multiple sheets are selected at once, the “top” sheet is the ActiveSheet. However, you can toggle the ActiveSheet within selected sheets.

Select a Sheet

Select Multiple Sheets

Use an array to select multiple sheets at once:

Worksheet Variable

Assigning a worksheet to an object variable allows you to reference the worksheet by it’s variable name. This can save a lot of typing and make your code easier to read. There are also many other reasons you might want to use variables.

To declare a worksheet variable:

Assign a worksheet to a variable:

Now you can reference the worksheet variable in your code:

Loop Through All Sheets in Workbook

Worksheet variables are useful when you want to loop through all the worksheets in a workbook. The easiest way to do this is:

This code will loop through all worksheets in the workbook, displaying each worksheet name in a message box. Looping through all the sheets in a workbook is very useful when locking / unlocking or hiding / unhiding multiple worksheets at once.

Worksheet Protection

Workbook Protection

Workbook protection locks the workbook from structural changes like adding, deleting, moving, or hiding worksheets.

You can turn on workbook protection using VBA:

or disable workbook protection:

Note: You can also protect / unprotect without a password by omitting the Password argument:

Worksheet Protection

Worksheet-level protection prevents changes to individual worksheets.

Protect Worksheet

Unprotect Worksheet

There are a variety of options when protecting worksheets (allow formatting changes, allow user to insert rows, etc.) We recommend using the Macro Recorder to record your desired settings.

We discuss worksheet protection in more detail here.

Worksheet Visible Property

You might already know that worksheets can be hidden:

There are actually three worksheet visibility settings: Visible, Hidden, and VeryHidden. Hidden sheets can be unhidden by any regular Excel user – by right-clicking in the worksheet tab area (shown above). VeryHidden sheets can only be unhidden with VBA code or from within the VBA Editor. Use the following code examples to hide / unhide worksheets:

Unhide Worksheet

Hide Worksheet

Very Hide Worksheet

Worksheet-Level Events

Events are triggers that can cause “Event Procedures” to run. For example, you can cause code to run every time any cell on a worksheet is changed or when a worksheet is activated.

Worksheet event procedures must be placed in a worksheet module:

There are numerous worksheet events. To see a complete list, go to a worksheet module , select “Worksheet” from the first drop-down. Then selecting an event procedure from the second drop-down to insert it into the module.

Worksheet Activate Event

Worksheet activate events run each time the worksheet is opened.

This code will select cell A1 (resetting the view area to the top-left of the worksheet) each time the worksheet is opened.

Worksheet Change Event

Worksheet change events run whenever a cell value is changed on the worksheet. Read our tutorial about Worksheet Change Events for more information.

Worksheet Cheat Sheet

Below you will find a cheat sheet containing common code examples for working with sheets in VBA

VBA Worksheets Cheatsheet

VBA worksheets Cheatsheet

Description Code Example
Referencing and Activating Sheets
Tab Name Sheets(«Input»).Activate
VBA Code Name Sheet1.Activate
Index Position Sheets(1).Activate
Select Sheet
Select Sheet Sheets(«Input»).Select
Set to Variable Dim ws as Worksheet
Set ws = ActiveSheet
Name / Rename ActiveSheet.Name = «NewName»
Next Sheet ActiveSheet.Next.Activate
Loop Through all Sheets Dim ws as Worksheet

For each ws in Worksheets
Msgbox ws.name
Next ws Loop Through Selected Sheets Dim ws As Worksheet

For Each ws In ActiveWindow.SelectedSheets
MsgBox ws.Name
Next ws Get ActiveSheet MsgBox ActiveSheet.Name Add Sheet Sheets.Add Add Sheet and Name Sheets.Add.Name = «NewSheet» Add Sheet With Name From Cell Sheets.Add.Name = range(«a3»).value Add Sheet After Another Sheets.Add After:=Sheets(«Input») Add Sheet After and Name Sheets.Add(After:=Sheets(«Input»)).Name = «NewSheet» Add Sheet Before and Name Sheets.Add(Before:=Sheets(«Input»)).Name = «NewSheet» Add Sheet to End of Workbook Sheets.Add After:=Sheets(Sheets.Count) Add Sheet to Beginning of Workbook Sheets.Add(Before:=Sheets(1)).Name = «FirstSheet» Add Sheet to Variable Dim ws As Worksheet
Set ws = Sheets.Add Copy Worksheets Move Sheet to End of Workbook Sheets(«Sheet1»).Move After:=Sheets(Sheets.Count) To New Workbook Sheets(«Sheet1»).Copy Selected Sheets To New Workbook ActiveWindow.SelectedSheets.Copy Before Another Sheet Sheets(«Sheet1»).Copy Before:=Sheets(«Sheet2») Before First Sheet Sheets(«Sheet1»).Copy Before:=Sheets(1) After Last Sheet Sheets(«Sheet1»).Copy After:=Sheets(Sheets.Count) Copy and Name Sheets(«Sheet1»).Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = «LastSheet» Copy and Name From Cell Value Sheets(«Sheet1»).Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = Range(«A1»).Value To Another Workbook Sheets(«Sheet1»).Copy Before:=Workbooks(«Example.xlsm»).Sheets(1) Hide / Unhide Sheets Hide Sheet Sheets(«Sheet1»).visible = False
or
Sheets(«Sheet1»).visible = xlSheetHidden Unhide Sheet Sheets(«Sheet1»).Visible = True
or
Sheets(«Sheet1»).Visible = xlSheetVisible Very Hide Sheet Sheets(“Sheet1”).Visible = xlSheetVeryHidden Delete or Clear Sheets Delete Sheet Sheets(«Sheet1»).Delete Delete Sheet (Error Handling) On Error Resume Next
Sheets(«Sheet1»).Delete
On Error GoTo 0 Delete Sheet (No Prompt) Application.DisplayAlerts = False
Sheets(«Sheet1»).Delete
Application.DisplayAlerts = True Clear Sheet Sheets(«Sheet1»).Cells.Clear Clear Sheet Contents Only Sheets(«Sheet1»).Cells.ClearContents Clear Sheet UsedRange Sheets(«Sheet1»).UsedRange.Clear Protect or Unprotect Sheets Unprotect (No Password) Sheets(«Sheet1»).Unprotect Unprotect (Password) Sheets(«Sheet1»).Unprotect «Password» Protect (No Password) Sheets(«Sheet1»).Protect Protect (Password) Sheets(«Sheet1»).Protect «Password» Protect but Allow VBA Access Sheets(«Sheet1»).Protect UserInterfaceOnly:=True Unprotect All Sheets Dim ws As Worksheet

For Each ws In Worksheets
ws.Unprotect «password»
Next ws

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

Источник

Like this post? Please share to your friends:
  • Excel vba workbooks worksheets
  • Excel vba this workbook open
  • Excel vba workbook workbooks
  • Excel vba this workbook close
  • Excel vba workbook saveas