Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

hiding sheets

Status
Not open for further replies.

sedgely

Technical User
Feb 21, 2002
406
GB
i have the following code which hides all sheets except the one named
Code:
Function hideAll()
Dim ws As Worksheet
 For Each ws In ThisWorkbook.Worksheets
  If ws.Name <> "MainMenu" Then ws.Visible = xlSheetVeryHidden
Next
End Function
What I want to do is to hide sheets based on a list of sheet names given on sheet1. so if range A1:A10 contains a list of sheet names i want the code to hide those sheets. any pointers on how i can modify my code to make this happen?

Cheers, Craig
Si fractum non sit, noli id reficere
 
Craig,

A very simple version with no error checking:
Code:
Function hideAll()
Dim oCell As Range

 For Each oCell In ThisWorkbook.Worksheets("Sheet1").Range("A1:A10")
   ThisWorkbook.Worksheets(oCell.Text).Visible = xlSheetVeryHidden
 Next oCell

End Function


Regards,
Mike
 
Hi Craig,

Try this ...

Code:
Function hideAll()
    Dim arrWs(), i As Long
    With ThisWorkbook
        arrWs = .Sheets("Sheet1").Range("A1:A10").Value
        On Error Resume Next 'for bad sheet names or missing array items
        For i = LBound(arrWs) To UBound(arrWs)
            If .Sheets(arrWs(i, 1)).Name <> "MainMenu" Or .Sheets.Count > 1 Then
                .Sheets(arrWs(i, 1)).Visible = xlSheetVeryHidden
            End If
        Next i
    End With
End Function

-----------
Regards,
Zack Barresse
 
Try this...
Function hideAll()
Dim ws As Worksheet
c = 0
For Each A In Range("a1:a10")
ws(c) = A.Text
Sheets(ws(c)).Visible = xlSheetVeryHidden
c = c + 1
Next A
 
Thanx guys
Went with firefytr's solution, saves me adding the error trappin [roll1]

Cheers, Craig
Si fractum non sit, noli id reficere
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top