Thủ Thuật
  • TOP Thủ Thuật
    • Thủ Thuật Internet
    • Thủ Thuật Máy Tính
    • Thủ Thuật Tiện Ích
    • Thủ Thuật Phần Mềm
  • Chia Sẻ Kiến Thức
    • Học Excel
    • Học Word
    • Học Power Point
  • Games
  • Kênh Công Nghệ
  • Facebook
  • WordPress
  • SEO
No Result
View All Result
Thủ Thuật
  • TOP Thủ Thuật
    • Thủ Thuật Internet
    • Thủ Thuật Máy Tính
    • Thủ Thuật Tiện Ích
    • Thủ Thuật Phần Mềm
  • Chia Sẻ Kiến Thức
    • Học Excel
    • Học Word
    • Học Power Point
  • Games
  • Kênh Công Nghệ
  • Facebook
  • WordPress
  • SEO
No Result
View All Result
Thủ Thuật
No Result
View All Result
Home Chia Sẻ Kiến Thức Học Excel

How to Hide and Unhide Multiple Excel Sheets Instantly Using VBA

How to Hide and Unhide Multiple Excel Sheets Instantly Using VBA
6k
SHARES
19.5k
VIEWS
Share on Facebook

Nội Dung Bài Viết

Toggle
  • Instantly Unhide All Sheets in a Workbook
  • Hide Specific Sheets by Name
  • Hide All Sheets Except the Last One
  • Conclusion
  • References

By default, Microsoft Excel restricts users to hiding or unhiding worksheets one at a time via the right-click context menu. While this standard interface works fine for small files, it becomes a significant productivity bottleneck when managing complex workbooks with dozens of data tabs.

Efficiency is paramount in data management. Consequently, relying on manual clicks to toggle sheet visibility is not only tedious but also prone to errors. Fortunately, by leveraging Visual Basic for Applications (VBA), you can bypass these interface limitations. In this guide, “Thủ Thuật” will walk you through creating simple yet powerful macros to hide or unhide multiple sheets simultaneously, streamlining your Excel workflow.

Instantly Unhide All Sheets in a Workbook

A common scenario involves receiving a workbook where the previous author has hidden several calculation sheets. Manually unhiding them requires right-clicking, selecting “Unhide,” choosing a sheet, and repeating the process for every single hidden tab.

To automate this, we use a For - Next loop in VBA to iterate through every worksheet in the workbook and set its Visible property to True. The following code also includes an error handler to ensure the script runs smoothly without crashing if an unexpected issue arises.

VBA Code to Unhide All Sheets:

Sub UnhideAllSheets()
    On Error GoTo ErrorHandler
    Dim ws As Worksheet

    ' Loop through each worksheet in the active workbook
    For Each ws In ThisWorkbook.Worksheets
        ws.Visible = True
    Next ws

    Exit Sub

ErrorHandler:
    MsgBox "An error occurred: " & Err.Description
End Sub

Hide Specific Sheets by Name

Sometimes, you need to hide specific sheets to prepare a report for presentation or to protect reference data from accidental edits. Instead of hiding them manually, you can define exactly which sheets should disappear using their names.

Xem thêm:  Master Excel Pivot Tables: A Comprehensive Guide to Analyzing Sales Data

The script below targets “Sheet1” and “Sheet2”. You can customize this by replacing the names inside the quotation marks with the actual names of the tabs in your workbook.

VBA Code to Hide Specific Sheets:

Sub HideSpecificSheets()
    On Error GoTo ErrorHandler

    ' Set specific sheets to hidden
    Worksheets("Sheet1").Visible = xlSheetHidden
    Worksheets("Sheet2").Visible = xlSheetHidden

    Exit Sub

ErrorHandler:
    MsgBox "An error occurred: " & Err.Description
End Sub

When you need to bring these specific sheets back, you simply reverse the logic. By changing the property from xlSheetHidden to xlSheetVisible, the sheets will reappear instantly.

Animation demonstrating the interface for managing sheet visibility in ExcelAnimation demonstrating the interface for managing sheet visibility in Excel

VBA Code to Unhide Specific Sheets:

Sub UnhideSpecificSheets()
    On Error GoTo ErrorHandler

    ' Set specific sheets to visible
    Worksheets("Sheet1").Visible = xlSheetVisible
    Worksheets("Sheet2").Visible = xlSheetVisible

    Exit Sub

ErrorHandler:
    MsgBox "An error occurred: " & Err.Description
End Sub

Hide All Sheets Except the Last One

A crucial technical constraint in Excel is that a workbook cannot hide every single sheet; at least one sheet must remain visible at all times. If you attempt to hide all sheets, Excel will throw a runtime error.

To handle this, we can use a loop that iterates through the sheets but stops before the final one. The logic uses Worksheets.Count - 1 to ensure the loop covers all sheets except the very last one in the index.

VBA Code to Hide All But the Last Sheet:

Sub HideAllExceptLastSheet()
    On Error GoTo ErrorHandler
    Dim i As Integer

    ' Loop from the first sheet to the second-to-last sheet
    For i = 1 To Worksheets.Count - 1
        Worksheets(i).Visible = xlSheetHidden
    Next i

    Exit Sub

ErrorHandler:
    MsgBox "An error occurred: " & Err.Description
End Sub

In this script, the integer variable i represents the index number of the sheet. This method is particularly useful when you want to create a “Dashboard” style workbook where only the main interface sheet (positioned as the last tab) is visible to the user initially.

Xem thêm:  Lọc Danh Sách Ngày Cuối Tuần trong Excel với Advanced Filter

Conclusion

Managing sheet visibility in Excel does not have to be a manual, time-consuming chore. By utilizing the VBA examples provided above, you can toggle the visibility of multiple sheets instantly, ensuring your workbooks are both clean and functional.

Whether you are unhiding an entire model for audit or hiding raw data sheets for a clean presentation, these macros are essential tools for any serious Excel user. We encourage you to copy these codes into your personal macro workbook to have them ready whenever needed. For more advanced Excel techniques and automation tips, continue exploring the comprehensive guides here at “Thủ Thuật”.

References

  • Microsoft Support: Automate tasks with the Macro Recorder
  • Excel Developers: Worksheet.Visible Property (Excel)
  • TechCommunity: VBA Best Practices for Excel Automation
Đánh Giá Bài Viết
Tuyết Nhi

Tuyết Nhi

Tôi là Tuyết Nhi - Nữ phóng viên trẻ đến từ Hà Nội. Với niềm đam mê công nghệ, khoa học kỹ thuật, tôi yêu thích và muốn chia sẻ đến mọi người những trải nghiệm, kinh nghiệm về các lĩnh vực công nghệ, kỹ thuật... Rất mong được quý độc giả đón nhận ❤️.

Related Posts

How to Generate Unique Random Numbers in Excel: A Comprehensive Guide
Học Excel

How to Generate Unique Random Numbers in Excel: A Comprehensive Guide

Master the Excel ERROR.TYPE Function to Categorize and Fix Formula Errors
Học Excel

Master the Excel ERROR.TYPE Function to Categorize and Fix Formula Errors

How to Print A5 Pages on A4 Paper: A Complete Guide
Học Excel

How to Print A5 Pages on A4 Paper: A Complete Guide

How to Create a Professional Plan vs. Actual Chart in Excel
Học Excel

How to Create a Professional Plan vs. Actual Chart in Excel

Discussion about this post

Trending.

Trích Xuất Dữ Liệu từ Báo Cáo Power BI Đã Xuất Bản Trên Web

Trích Xuất Dữ Liệu từ Báo Cáo Power BI Đã Xuất Bản Trên Web

Hướng Dẫn Cách Livestream Trên Facebook Bằng Điện Thoại Và Máy Tính Đơn Giản, Sắc Nét Từ A-Z

Hướng Dẫn Cách Livestream Trên Facebook Bằng Điện Thoại Và Máy Tính Đơn Giản, Sắc Nét Từ A-Z

Download Your Uninstaller Pro 7.5 Full Key 2025 – Giải Pháp Gỡ Cài Đặt Phần Mềm Tận Gốc

Download Your Uninstaller Pro 7.5 Full Key 2025 – Giải Pháp Gỡ Cài Đặt Phần Mềm Tận Gốc

Day R Premium MOD APK: Sinh tồn hậu tận thế trên di động

Day R Premium MOD APK: Sinh tồn hậu tận thế trên di động

Hướng Dẫn Tích Hợp Akismet Vào Contact Form 7: Giải Pháp Chống Spam “Tàng Hình” Hiệu Quả Nhất

Hướng Dẫn Tích Hợp Akismet Vào Contact Form 7: Giải Pháp Chống Spam “Tàng Hình” Hiệu Quả Nhất

Giới Thiệu

Thủ Thuật

➤ Website đang trong quá trình thử nghiệm AI biên tập, mọi nội dung trên website chúng tôi không chịu trách nhiệm. Bạn hãy cân nhắc thêm khi tham khảo bài viết, xin cảm ơn!

Chuyên Mục

➤ TOP Thủ Thuật

➤ Chia Sẻ Kiến Thức

➤ Kênh Công Nghệ

➤ SEO

➤ Games

Liên Kết

➤ Ketquaxskt.com

➤ TOP Restaurants

➤ Here Restaurant

➤

➤

Liên Hệ

➤ TP. Hải Phòng, Việt Nam

➤ 0931. 910. JQK

➤ Email: [email protected]

Website này cũng cần quảng cáo, không có tiền thì viết bài làm sao  ” Đen Vâu – MTP ”

DMCA.com Protection Status

© 2025 Thủ Thuật - Website chia sẻ kiến thức công nghệ hàng đầu Việt Nam

No Result
View All Result
  • TOP Thủ Thuật
    • Thủ Thuật Internet
    • Thủ Thuật Máy Tính
    • Thủ Thuật Tiện Ích
    • Thủ Thuật Phần Mềm
  • Chia Sẻ Kiến Thức
    • Học Excel
    • Học Word
    • Học Power Point
  • Games
  • Kênh Công Nghệ
  • Facebook
  • WordPress
  • SEO

© 2025 Thủ Thuật - Website chia sẻ kiến thức công nghệ hàng đầu Việt Nam