Skip to content

Instantly share code, notes, and snippets.

@quickstep25
Last active May 4, 2024 22:08
Show Gist options
  • Save quickstep25/69ed165bff33301b251ed563be19d43f to your computer and use it in GitHub Desktop.
Save quickstep25/69ed165bff33301b251ed563be19d43f to your computer and use it in GitHub Desktop.
Code to unhide all Excel worksheets within a workbook.
' PASTE INTO IMMEDIATE WINDOW
for each sh in worksheets: sh.visible=true: next sh
' MACRO to unhide all workbook worksheets
Sub Unhide_All_Sheets()
Dim wks As Worksheet
For Each wks In ActiveWorkbook.Worksheets
wks.Visible = xlSheetVisible
Next wks
End Sub
' MACRO to unhide all sheets and display count
Sub Unhide_All_Sheets_Count()
Dim wks As Worksheet
Dim count As Integer
count = 0
For Each wks In ActiveWorkbook.Worksheets
If wks.Visible <> xlSheetVisible Then
wks.Visible = xlSheetVisible
count = count + 1
End If
Next wks
If count > 0 Then
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 worksheets with a specific word in the sheet name
Sub Unhide_Sheets_Contain()
Dim wks As Worksheet
Dim count As Integer
count = 0
For Each wks In ActiveWorkbook.Worksheets
If (wks.Visible <> xlSheetVisible) And (InStr(wks.Name, "report") > 0) Then
wks.Visible = xlSheetVisible
count = count + 1
End If
Next wks
If count > 0 Then
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment