Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default RE Any ideas why this simple proc. won't work?

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)

"Steph" wrote in message
m...
I get a Compile Error: Invalid Outside Procedure error, and the
debugger highlights the sheet name in the Shtarray "Dom P&L Ship".
I'm obviously screwing up syntax somewhere! Thanks!


Public Shtarray As Sheets
Public sht As Worksheet

Shtarray = Array("Dom P&L Ship", "Cons P&L Ship")

Sub ShowAnnually2003()

For Each sht In Shtarray
Workbook.Sheet(sht).Columns("A:D").EntireColumn.Hi dden = True
Next

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default RE Any ideas why this simple proc. won't work?

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)

"Steph" wrote in message
om...
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)

"Steph" wrote in message
m...
I get a Compile Error: Invalid Outside Procedure error, and the
debugger highlights the sheet name in the Shtarray "Dom P&L Ship".
I'm obviously screwing up syntax somewhere! Thanks!


Public Shtarray As Sheets
Public sht As Worksheet

Shtarray = Array("Dom P&L Ship", "Cons P&L Ship")

Sub ShowAnnually2003()

For Each sht In Shtarray
Workbook.Sheet(sht).Columns("A:D").EntireColumn.Hi dden = True
Next

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default RE Any ideas why this simple proc. won't work?

Yes. Check out the CodeName property.

--
George Nicholson

Remove 'Junk' from return address.


"Steph" wrote in message
om...
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)

"Steph" wrote in message
m...
I get a Compile Error: Invalid Outside Procedure error, and the
debugger highlights the sheet name in the Shtarray "Dom P&L Ship".
I'm obviously screwing up syntax somewhere! Thanks!


Public Shtarray As Sheets
Public sht As Worksheet

Shtarray = Array("Dom P&L Ship", "Cons P&L Ship")

Sub ShowAnnually2003()

For Each sht In Shtarray
Workbook.Sheet(sht).Columns("A:D").EntireColumn.Hi dden = True
Next

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vlookup won't work, any other ideas? Huw Excel Worksheet Functions 0 February 17th 05 04:31 PM
Assign Macro to button in Excel doesnt work Any ideas? Mike@Becketts Excel Discussion (Misc queries) 2 December 20th 04 02:47 PM
formula from Excel97 doesn't work in Excel2003,any ideas why? nic Excel Worksheet Functions 6 November 8th 04 04:40 PM
Any ideas why this simple proc. won't work? Steph[_3_] Excel Programming 1 June 4th 04 04:00 PM
Any ideas... Doesn't work... Andrew Slentz Excel Programming 1 May 10th 04 06:43 PM


All times are GMT +1. The time now is 06:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"