Hiding/UnHiding Selected Worksheets

C

Craig

Hi Again... how do I go about hiding/unHiding a selected set of worksheets
eg: I have worksheets named shHol1 thru shHol100 , how would I hide or
unhide sheets 20 thru 32? This is the vba names, not the actual sheet names
in excel... the sheets names are Jan - Dec.

Thanks again!
Craig
 
G

Guest

Craig, here are a couple of methods, one is using the date formating
facilities and the other uses an array where there may be international
language concerns.

'--> method 1
Sub SheetsShow()
ShowSheets True
End Sub

Sub SheetsHide()
ShowSheets False
End Sub

Sub ShowSheets(ByVal Hide As Boolean)

Dim i As Integer

For i = 1 To 12
ActiveWorkbook.Worksheets(Format(DateSerial(2000, i, 1), "Mmm")).Visible
= Hide
Next i

End Sub

'--> method 2
Sub SheetsShowInternational()
ShowSheets True
End Sub

Sub SheetsHideInternational()
ShowSheets False
End Sub


Sub ShowSheetsInternational()
Dim m As Variant
Dim mm As Variant
m = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec")
For Each mm In m
ActiveWorkbook.Worksheets(mm).Visible = Hide
Next mm
End Sub
 
C

Craig

thank Martin, I used the array("Jan", "Feb",... method and it worked fine.
I'm having a problem understanding one part of the code; though. When you
declare "M" as Variant and set "M" as array("Jan","Feb",...
In the For Each mm in m

I don't understand how or when "mm" was set?

Craig
 
G

Guest

This is a for each loop and each item in the array is used.

mm is set at the start of the loop and the next array item is used when the
code reaches the next mm statement.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top