Đề Xuất 6/2023 # A Macro To Unhide All Hidden Sheets In An Excel Workbook # Top 8 Like | Beiqthatgioi.com

Đề Xuất 6/2023 # A Macro To Unhide All Hidden Sheets In An Excel Workbook # Top 8 Like

Cập nhật nội dung chi tiết về A Macro To Unhide All Hidden Sheets In An Excel Workbook mới nhất trên website Beiqthatgioi.com. Hy vọng thông tin trong bài viết sẽ đáp ứng được nhu cầu ngoài mong đợi của bạn, chúng tôi sẽ làm việc thường xuyên để cập nhật nội dung mới nhằm giúp bạn nhận được thông tin nhanh chóng và chính xác nhất.

Unhiding Excel sheets is easy, but can be tedious. Use this simple macro to unhide all hidden sheets in an Excel workbook.

We hide sheets for many reasons, but mostly, to keep other people out of them. We rarely hide them from ourselves. When you need to update or fix a workbook for a user, you have to remember the hidden sheets and then unhide them – which is easy enough, unless you removed that functionality from the workbook!

Doing this several times to unhide all hidden sheets isn’t necessary. Here’s a quick macro that you can copy into almost any workbook to quickly unhide sheets:

Sub UnhideAllSheets()

‘Unhide all sheets in workbook.

Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets

ws.Visible = xlSheetVisible

Next ws

End Sub

In a nutshell, a For Each loop cycles through all the sheets in the Worksheets collection and sets each sheet’s Visible property to true. This macro will even unhide sheets you hide via the Visual Basic Editor properties (xlSheetVeryHidden) so be careful how you apply it.

Like most macros, this one has limited appeal. If you have only a few hidden sheets and you seldom need to unhide them, it’s just as easy to manually unhide them. If, on the other hand, this is a frequent task, you’ll probably find this one useful.

It’s a good demonstration of how easy it is to cycle through an object collection. You could add an If() statement that checks for the Visible property and then change only the ones that require it, but this loop is more efficient. Just reset them all; in this case, an If() just adds more work. However, if you want to avoid unhiding certain sheets or the “very hidden” sheets, an If() statement will do the trick.

Unhiding All Worksheets Within An Excel Workbook

Although you can quickly hide as many worksheets within a workbook as you like, we’re still limited to unhiding individual worksheets one at a time – unless you’re aware of Excel’s Custom Views feature. Fortunately, there is another way to avoid the agony of manually unhiding worksheets one at a time.

In this article I’ll show you how to use a single line of programming code to unhide the worksheets. Programming code in Excel is often referred to as macros. In this case we’re not creating a permanent macro, but rather typing a line of code to run on demand.

Figure 1: There are a variety of ways to hide worksheets in Excel.

Figure 2: Unfortunately, you must unhide worksheets one at a time.

You probably don’t have the time or inclination to unhide more than a couple of worksheets in this fashion, so instead we’ll use a bit of programming code to instantly display all worksheets at once:

As illustrated in Figure 3, press Alt-F11 on your keyboard to display Excel’s Visual Basic Editor. Mac users should press Fn-Alt-F11. Although it looks like a separate program, it’s a hidden aspect of Excel that most users haven’t seen before.

Select Immediate Window from the View menu, or press Ctrl-G on your keyboard (for Mac, Ctrl-Cmd-G).

At this point the Immediate window will appear on-screen. This is a special area where any programming code you type will be executed immediately, hence the name.

Type the following line of programming code into the Immediate window exactly as written below, and press Enter.

For Each s In Sheets: s.Visible = True: Next

The downside of the Immediate Window is you don’t get any direct feedback if your programming code worked, other than seeing that all of your worksheets are now visible within the workbook. Error prompts will appear if you press Enter when the line of code is either incomplete or contains typographical errors.

You may also encounter an error if the workbook is protected by way of the Protect Workbook command on Excel’s Review menu.

You can safely exit the Visual Basic Editor once you’ve run the line of code.

Figure 3: A single line of code in the Immediate Window will unhide all worksheets in the workbook.

The aforementioned line of code utilizes Visual Basic for Applications in Microsoft Excel. This is known as an object-oriented programming language, so if you want a little insight as to what the macro is doing:

For Each sets up a loop.

s is a variable that serves as a temporary placeholder for a worksheet to be acted on.

Sheets is a collection of all worksheets within the workbook. This actually includes other types of sheets as well, meaning Chart Sheets and Macro Worksheets. We could be more specific and use the Worksheets collection instead, but Sheets results in less typing.

Each worksheet has a Visible property, and in this case we’re setting it to True. The setting gets set to False when you hide a worksheet.

Next simply instructs Excel to skip to the next worksheet in succession, until all have been processed.

If you were to store this within a formal macro, the code might take this form:

For each s in Sheets

s.Visible

Next

The Immediate Window only allows us to execute a single line of code at a time, so the colons allow us to string three lines of code together into a single line that can be executed.

How To Unhide Sheets In Excel: Show Multiple Or All Sheets At Once

How to unhide sheets in Excel

If you want to see just one or two hidden sheets, here’s how you can quickly unhide them:

Note. Excel’s Unhide option only allows you to select one sheet at a time. To unhide multiple sheets, you will have to repeat the above steps for each worksheet individually or you can unhide all sheets in one go by using the below macros.

How to unhide sheets in Excel with VBA

In situations when you have multiple hidden worksheets, unhiding them one-by-one might be very time consuming, especially if you’d like to unhide all the sheets in your workbook. Fortunately, you can automate the process with one of the following macros.

How to unhide all sheets in Excel

This small macro makes all hidden sheets in an active workbook visible at once, without disturbing you with any notifications.

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

Show all hidden sheets and display their count

Like the above one, this macro also displays all hidden sheets in a workbook. The difference is that upon completion, it shows a dialog box informing the user how many sheets have been unhidden:

Sub Unhide_All_Sheets_Count() Dim wks As Worksheet Dim count As Integer count = 0 For Each wks In ActiveWorkbook.Worksheets wks.Visible = xlSheetVisible count = count + 1 End If Next wks MsgBox count & " worksheets have been unhidden.", vbOKOnly, "Unhiding worksheets" Else MsgBox "No hidden worksheets have been found.", vbOKOnly, "Unhiding worksheets" End If End Sub

Unhide multiple sheets that you select

If you’d rather not unhide all worksheets at once, but only those that the user explicitly agrees to make visible, then have the macro ask about each hidden sheet individually, like this:

Sub Unhide_Selected_Sheets() Dim wks As Worksheet Dim MsgResult As VbMsgBoxResult For Each wks In ActiveWorkbook.Worksheets If wks.Visible = xlSheetHidden Then MsgResult = MsgBox("Unhide sheet " & chúng tôi & "?", vbYesNo, "Unhiding worksheets") If MsgResult = vbYes Then wks.Visible = xlSheetVisible End If Next End Sub

Unhide worksheets with a specific word in the sheet name

In situations when you only want to unhide sheets containing certain text in the their names, add an IF statement to the macro that will check the name of each hidden worksheet and unhide only those sheets that contain the text you specify.

In this example, we unhide sheets with the word ” report” in the name. The macro will display sheets such as Report, Report 1, July report, and the like.

To unhide worksheets whose names contain some other word, replace ” report” in the following code with your own text.

Sub Unhide_Sheets_Contain() Dim wks As Worksheet Dim count As Integer count = 0 For Each wks In ActiveWorkbook.Worksheets wks.Visible = xlSheetVisible count = count + 1 End If Next wks MsgBox count & " worksheets have been unhidden.", vbOKOnly, "Unhiding worksheets" Else MsgBox "No hidden worksheets with the specified name have been found.", vbOKOnly, "Unhiding worksheets" End If End Sub

How to use the macros to unhide sheets in Excel

To use the macros in your worksheet, you can either copy/paste the code in the Visual Basic Editor or download the workbook with the macros and run them from there.

How to insert the macro in your workbook

You can add any of the above macros to your workbook in this way:

Open the workbook with hidden sheets.

Press Alt + F11 to open the Visual Basic Editor.

Paste the code in the Code window.

Press F5 to run the macro.

For the detailed step-by-step instructions, please see How to insert and run VBA code in Excel.

Download the workbook with the macros

Alternatively, you can download our sample workbook to unhide sheets in Excel that contains all of the macros discussed in this tutorial:

Unhide_All_Sheets – unhide all worksheets in an active workbook momentarily and silently.

Unhide_All_Sheets_Count­ – show all hidden sheets along with their count.

Unhide_Selected_Sheets – display hidden sheets you choose to unhide.

Unhide_Sheets_Contain – unhide worksheets whose names contain a specific word or text.

To run the macros in your Excel, you do the following:

Open the downloaded workbook and enable the macros if prompted.

Open your own workbook in which you want to see hidden sheets.

For example, to unhide all sheets in your Excel file and display the hidden sheets count, you run this macro:

How to show hidden sheets in Excel by creating a custom view

So, what we are going to do now is create the Show All Sheets custom view. Here’s how:

That’s it! All hidden sheets will be shown immediately.

Note. This method does not show very hidden sheets. The only way to view such sheets is to unhide them with VBA.

Cannot unhide sheets in Excel – problems and solutions

If you are unable to unhide certain sheets in your Excel, the following troubleshooting tips may shed some light why.

1. The workbook is protected

2. Worksheets are very hidden

If your worksheets are hidden by VBA code that makes them very hidden (assigns the xlSheetVeryHidden property), such worksheets cannot be displayed by using the Unhide command. To unhide very hidden sheets, you need to change the property from xlSheetVeryHidden to xlSheetVisible from within the Visual Basic Editor or run this VBA code.

3. There are no hidden sheets in the workbook

This is how you unhide sheets in Excel. If you are curious to know how to hide or unhide other objects such as rows, columns or formulas, you will find full details in the below articles. I thank you for reading and hope to see you on our blog next week!

Macros to unhide worksheets in Excel

You may also be interested in

How To Add Macro Code To Excel Workbook

How to copy Excel macro VBA code to your workbook, from website or sample file. Different types of code, where to paste it. Step-by-step videos, written steps.

Copy Excel VBA Code to a Regular Module

To see the steps for pasting a macro into a workbook, and running the macro, please watch this short video tutorial. The written instructions are below the video.

Copy Excel VBA Code to a Regular Module

Instead of starting from scratch, if you need an Excel macro, you can often find sample code at reputable sites on the internet. To copy that code, and add it to one of your workbooks, follow these steps:

Copy the sample code that you want to use

Open the workbook in which you want to add the code

Hold the Alt key, and press the F11 key, to open the Visual Basic Editor

To run the code:

Copy Excel VBA Code to a Worksheet Module

Worksheet event code is stored on a worksheet module. To add worksheet event code to your worksheet, do the following:

Copy the code that you want to use

Select the worksheet in which you the code to run

Copy Excel VBA Code to a Workbook Module

Another type of code is Workbook Event code, which should be added to the workbook code module:

Copy the code that you want to use

Select the workbook in which you want to store the code

Hold the Alt key, and press the F11 key, to open the Visual Basic Editor

In the Project Explorer, find your workbook, and open the list of Microsoft Excel Objects

Copy Excel VBA Code From a Different Workbook

To see the steps for copying a macro from one workbook to another, in any version of Excel, please watch this short video tutorial. The written instructions are below the video.

Copy Excel VBA Code From a Different Workbook

You may find code in a sample workbook online, and decide to add it to one of your workbooks. You can copy all the code in a module by doing the following:

Open both workbooks

Hold the Alt key, and press the F11 key, to open the Visual Basic Editor

In the Project Explorer, find your workbook, and the workbook with the code that you want to copy. The screenshot at the right, the code is in chúng tôi and will be copied to MyForm.xlsm

Release the mouse button, and a copy of the module will appear in the workbook.

To run the code:

Allow Macros to Run in Your Workbook

To use macros in Excel, you might need to enable them when the file opens. If you are using macros for the first time on your current computer, you might also need to adjust the macro security settings.

Follow the instructions below, to make these changes.

Enable Macros When Opening the File

When you open a workbook that contains macros, you might see a security warning, at the top of the worksheet, above the Formula Bar.

Check Your Macro Security Settings

If you haven’t run macros before, you might need to change your macro security level. (You may have to clear this with your IT department.)

If you changed the setting, close the workbook, and then reopen it

Run an Excel Macro

After you copy a macro to a regular module, follow the steps below, to run the macro. If the macro does not run, check your macro settings.

To run an Excel macro:

Copy the macro code to a regular code module in your file.

Create a Worksheet Event Macro

To see the steps for creating an Excel Worksheet Change Event macro, watch this short video.

There are written steps on the Contextures Blog, and you can download the sample file used in this video.

Modify Copied Excel VBA Code

If you copy VBA code into your Excel file, you might need to make changes to the object names, or other settings, so that the code works correctly in your file. Here are three things to check, before you try to run the code in your file:

Check the Sheet Names and Ranges

If there are sheet names or range references in the code, you can modify them, to match your workbook.

In the code, look for references to “Worksheets” to “Sheets”, and change those to the sheet names in your workbook.

Also look for “Range” references, such as Range(“A1:G100”), and adjust those to match the location of your data.

These references might be at the top of the procedure, in a Set statement:

Set ws = Worksheets("SalesData")

or elsewhere in the code.

If you run the code without modifying the reference, you might see an error message: Run-time error ‘9’: Subscript out of range

Change the sheet name in the line that was highlighted, save the changes, and try the code again.

Add and Name Objects

If the code refers to objects on the worksheet, be sure to add those objects in your workbook, and use the correct object name in the code.

For example, in the code for the Data Validation Combo Box, you’ll need to add a combo box to the worksheet, and name it as TempCombo. Or, if your combo box has a different name, change the code references to match.

Specify the Target Columns or Rows

Some code is designed to run when a cell in a specific row or column is changed. For example, in the sample code shown below, there is a red dot on the line that says column 3 is the only one where the change will occur.

NOTE: In all of these examples, you could use Row instead of Column, to limit the target to specific rows.

A) In your workbook, if you want the code to run when a cell in column E is changed, you could change the 3 to a 5.

If Target.Column = 5 Then

B) Or, add more columns in the code. For example:

If Target.Column = 3 _ Or Target.Column = 5 _ Or Target.Column = 6 Then

C) If you don’t want to limit the code to a specific column, you could delete the two rows (If…End If) that are marked with red circles. In that case, the code will run for a change in every column.

Get the Sample File

To see examples of workbook modules, worksheet modules and regular code modules, download the Add Code to a Workbook sample file. The zipped file is in xlsm format, and contains macros. Be sure to enable macros when you open the file, if you want to test the macros.

Related Tutorials

Create an Excel UserForm Macro Troubleshooting Tips UserForm with ComboBoxes

Edit Your Recorded Macro

Last updated: April 14, 2021 1:25 PM

Bạn đang đọc nội dung bài viết A Macro To Unhide All Hidden Sheets In An Excel Workbook trên website Beiqthatgioi.com. Hy vọng một phần nào đó những thông tin mà chúng tôi đã cung cấp là rất hữu ích với bạn. Nếu nội dung bài viết hay, ý nghĩa bạn hãy chia sẻ với bạn bè của mình và luôn theo dõi, ủng hộ chúng tôi để cập nhật những thông tin mới nhất. Chúc bạn một ngày tốt lành!