I worked this code out in Excel 2003. Maybe it will help
with your solution to hiding or showing worksheets based
on two conditions. Try it out in the attached file.
Private Sub cmdHideSheets_Click()
'loop through sheet names listed in column H
'hide valid worksheets where column J cell contains "Tab" and column M cell does not contain "X"
Dim j As Integer, wks As Worksheet, otherWrkSheet As String
Set wks = Sheets("Sheet1")
j = 2 'starting row of other worksheet names in workbook
With wks
Do While Trim(.Cells(j, 8).Value) <> ""
otherWrkSheet = wks.Cells(j, 8).Value
If Valid_Worksheet(otherWrkSheet) Then
If UCase(.Cells(j, 10).Value) = "TAB" Then
Sheets(otherWrkSheet).Visible = UCase(.Cells(j, 13).Value) = "X"
End If
End If
j = j + 1
Loop
End With
Set wks = Nothing
End Sub
Private Function Valid_Worksheet(wsName As String) As Boolean
'return True if wsName is a valid worksheet name
Dim wSheet As Worksheet
On Error Resume Next
Set wSheet = Worksheets(wsName)
On Error GoTo 0
If Not wSheet Is Nothing Then Valid_Worksheet = True
End Function
Bookmarks