Hướng dẫn xóa tất cả các sheet ẩn trong file excel
![]() |
Hướng dẫn xóa tất cả các sheet ẩn trong file excel |
Bạn có 01 file excel có rất nhiều sheet và sheet ẩn, giờ bạn mình muốn xóa tất cả các sheet ẩn đi thì làm thế nào. Trong bài viết hôm nay it269 xin chia sẻ cho các bạn một đoạn code VBA nhỏ có thể giúp bạn xóa tất cả các sheet ần này đi một cách nhanh chóng
Các bước thực hiện:
Bước 1: Mở file excel mà bạn cần xóa các sheet ẩn lên.
Bước 2: Nhấn tổ hợp phím
Bước 3: Hộp thoại Microsoft Visual Basic for application hiện ra. Từ thanh menu click vào Insert - Module
Bước 4: Copy toàn bộ đoạn code VBA bên dưới dán vào
![]() |
Code VBA xóa tất cả các sheet ẩn trong file excel |
Bước 5: Nhấn F5 để chạy code và chờ trong giây lát việc xóa sheet ẩn mất thời gian nhiều hay ít nó còn phụ thuộc vào số lượng sheet ẩn trong file excel của bạn.
Sub DeleteHiddenSheets()
'PURPOSE: Remove any hidden sheets from the active workbook
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
'NOTE: This macro skips over Very Hidden sheets
Dim Removals As Long
'Turn Off Alerts
Application.DisplayAlerts = False
'Loop Through Each Sheet in Workbook
For Each sht In ActiveWorkbook.Sheets
'Test if Sheeet is Hidden
If sht.Visible = xlSheetHidden Then
sht.Delete
Removals = Removals + 1
End If
Next sht
'Turn Alerts Back On
Application.DisplayAlerts = True
'Report How Many Were Removed
If Removals = 1 Then
MsgBox "[1] sheet was removed from this workbook."
Else
MsgBox "[" & Removals & "] sheets were removed from this workbook."
End If
End Sub
Chúc các bạn thành công!
Đăng nhận xét