View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_5_] Jim Thomlinson[_5_] is offline
external usenet poster
 
Posts: 486
Default Hide and/or Unhide Worksheets

Give this a try...

Sub Test()
Call HideAllSheets("That")
End Sub

Private Sub HideAllSheets(ByVal SheetName As String)
Dim wks As Worksheet

If SheetExists(SheetName) Then
Sheets(SheetName).Visible = xlSheetVisible
For Each wks In Worksheets
If wks.Name < SheetName Then wks.Visible = xlSheetHidden
Next wks
Else
MsgBox "Error on sheet name."
End If
End Sub

Public Function SheetExists(SName As String, _
Optional ByVal Wb As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If Wb Is Nothing Then Set Wb = ThisWorkbook
SheetExists = CBool(Len(Wb.Sheets(SName).Name))
End Function

--
HTH...

Jim Thomlinson


"Rob" wrote:

I want to unhide the Vendor Worksheet only
(In this case it could be a Merchant Worksheet, Or a Procurement Worksheet)
I don't want to specify names of other worksheets that need to be hidden for
some may not be created as yet. I want to specify one sheet to be visible in
separate macros. So one macro would say unhide the Vendor Worksheet and hide
the rest. Another might say unhide the Merchant Worksheet and the Vendor
Worksheet and hide the rest.