How to Unhide/Make Visible multiple worksheets stored in an array ?

Pramodpandit123

New Member
Joined
Apr 18, 2020
Messages
30
Office Version
  1. 2016
Platform
  1. Windows
Whenever I run the following code i get "1004 Unable to set the visible property of the worksheet class" error while making the sheets visible. But it seems to perfectly work while hiding the sheets. How can i make the sheets stored in the array visible ?
P.S -> My worbook/worksheet is also not password protected.
VBA Code:
Sub sheets()
    Dim i As Long, c As Long
    Dim SheetArray() As String

    With ActiveSheet.ListBoxSh

        For i = 0 To .ListCount - 1
            If .Selected(i) = False Then
                ReDim Preserve SheetArray(c)
                SheetArray(c) = .List(i)
                c = c + 1
            End If
        Next i
        
        Sheets(SheetArray()).Visible = xlSheetHidden

         'SOME CODE HERE

        Sheets(SheetArray()).Visible = xlSheetVisible
            End With
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I'm not sure you can do it that way, better to iterate through the array

VBA Code:
    'Unhide sheets
    For I = LBound(SheetArray) To UBound(SheetArray)
            Worksheets(SheetArray(I)).Visible = xlSheetVisible
    Next I
 
Upvote 0
Solution

Forum statistics

Threads
1,214,827
Messages
6,121,818
Members
449,049
Latest member
cybersurfer5000

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