RE Any ideas why this simple proc. won't work?

S

Steph

Bob,

Thanks so much. Works great! One follow up if I may.....Rather than
using the Worksheet names "Sheet1" or "Sheet2" (or whatever they are
named), can I use the VBA name of the sheets as defined is the VBA
Properties window? My users are notorious for changing the sheet
names! Thanks!

Steph,

Try

Public Shtarray
Public sht As Worksheet

Sub ShowAnnually2003()
Shtarray = Array("Sheet1", "Sheet2")
For Each sht In Worksheets(Shtarray)
sht.Columns("A:D").EntireColumn.Hidden = True
Next sht

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
B

Bob Phillips

Steph,

Here is one way,

Public Shtarray

Sub ShowAnnually2003()
Dim i As Long
Dim dicSheets As Object
Set dicSheets = CreateObject("Scripting.Dictionary")
dicSheets.Add "A1", "A1"
dicSheets.Add "A2", "A2"

For Each sht In ActiveWorkbook.Worksheets
If dicSheets.exists(sht.CodeName) Then
sht.Columns("A:D").EntireColumn.Hidden = True
End If
Next sht

End Sub

The items added to the dictionary are the sheet codenames.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 

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