Retrieve hidden sheets name dynamically

Firasath

Board Regular
Joined
Feb 20, 2011
Messages
137
Office Version
  1. 365
Hi, can we retrieve all the hidden sheets names dynamically in one column either by formula or using VBA?
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
The below will list them in column A:
VBA Code:
Sub test()
  Dim ws As Worksheet, wsVar() As Variant, x As Long
  
  For Each ws In Sheets
    If Not ws.Visible Then
      ReDim Preserve wsVar(x): wsVar(x) = ws.Name: x = x + 1
    End If
  Next ws
  Range("A1").Resize(x) = Application.Transpose(wsVar)
End Sub

How do you mean "dynamically", does this mean you want the list to change when sheets are hidden/ made visible?
 
Upvote 0
The below will list them in column A:
VBA Code:
Sub test()
  Dim ws As Worksheet, wsVar() As Variant, x As Long
 
  For Each ws In Sheets
    If Not ws.Visible Then
      ReDim Preserve wsVar(x): wsVar(x) = ws.Name: x = x + 1
    End If
  Next ws
  Range("A1").Resize(x) = Application.Transpose(wsVar)
End Sub

How do you mean "dynamically", does this mean you want the list to change when sheets are hidden/ made visible?
Thanks for your prompt reply. Yes, as you mentioned, the list should get changed when the visible sheet change to hidden or vice versa.
 
Upvote 0
If you are hiding/ unhiding the sheets manually then you can try the below in the 'ThisWorkbook' module:
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  Dim ws As Worksheet, wsVar() As Variant, x As Long
  
  If Sh.Name <> "Sheet1" Then Exit Sub
  
  For Each ws In Sheets
    If Not ws.Visible Then
      ReDim Preserve wsVar(x): wsVar(x) = ws.Name: x = x + 1
    End If
  Next ws
  With Sheet1.Range("A1")
    .Resize(Sheets.Count).ClearContents
    If x > 0 Then .Resize(x) = Application.Transpose(wsVar)
  End With
End Sub

Where "Sheet1" in the code refers to the sheet where the sheet names will be listed.
 
Upvote 0
Solution
@Georgiboy shouldn’t this be before your Redim statement.
x = x + 1
On 2nd thoughts I suspect it works it’s just not intuitive (to me)
 
Upvote 0
If you are hiding/ unhiding the sheets manually then you can try the below in the 'ThisWorkbook' module:
VBA Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
  Dim ws As Worksheet, wsVar() As Variant, x As Long
 
  If Sh.Name <> "Sheet1" Then Exit Sub
 
  For Each ws In Sheets
    If Not ws.Visible Then
      ReDim Preserve wsVar(x): wsVar(x) = ws.Name: x = x + 1
    End If
  Next ws
  With Sheet1.Range("A1")
    .Resize(Sheets.Count).ClearContents
    If x > 0 Then .Resize(x) = Application.Transpose(wsVar)
  End With
End Sub

Where "Sheet1" in the code refers to the sheet where the sheet names will be listed.
Thanks a lot, it worked for me.
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top