Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Autoexec Macro

I would like to create a macro that, upon opening the
file, looks at each cell in Row two and if that cell has
the term "hide" then the macro will hide that column and
for every column in the range.

Column 1 2 3 4 5 6

row 1 SF LA NY Chi Bos Cle
row 2 hide view hide view view view

Any suggestion on how to code this?

Thank you.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Autoexec Macro

Brian,

Private Sub Workbook_Open()
Dim i As Long

For i = 1 To Cells(2, Columns.Count).End(xlToLeft).Column
If Cells(2, i).Value = "hide" Then
Cells(2, i).EntireColumn.Hidden = True
End If
Next

End Sub


--

HTH

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

"Briank" wrote in message
...
I would like to create a macro that, upon opening the
file, looks at each cell in Row two and if that cell has
the term "hide" then the macro will hide that column and
for every column in the range.

Column 1 2 3 4 5 6

row 1 SF LA NY Chi Bos Cle
row 2 hide view hide view view view

Any suggestion on how to code this?

Thank you.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Autoexec Macro

You can use this code for the Active sheet Brian

Dim Cnum As Integer
For Cnum = 1 To 256
If Cells(2, Cnum).Value = "hide" Then Columns(Cnum).Hidden = True
Next

See Chip Pearson his page about events
http://www.cpearson.com/excel/events.htm




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



"Briank" wrote in message ...
I would like to create a macro that, upon opening the
file, looks at each cell in Row two and if that cell has
the term "hide" then the macro will hide that column and
for every column in the range.

Column 1 2 3 4 5 6

row 1 SF LA NY Chi Bos Cle
row 2 hide view hide view view view

Any suggestion on how to code this?

Thank you.



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Autoexec Macro

Thanks for the input. The code works great.
However, when I four worksheets in my file and the code
only works for the first worksheet. Even though I have
copied the code into four objects I still get only one
worksheet with the correctly run code. Any thoughts?

-----Original Message-----
I would like to create a macro that, upon opening the
file, looks at each cell in Row two and if that cell has
the term "hide" then the macro will hide that column and
for every column in the range.

Column 1 2 3 4 5 6

row 1 SF LA NY Chi Bos Cle
row 2 hide view hide view view view

Any suggestion on how to code this?

Thank you.
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Autoexec Macro

This will work for all worksheets in the workbook
The event will run when you open the workbook

Private Sub Workbook_Open()
Dim Cnum As Integer
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
For Cnum = 1 To 256
If sh.Cells(2, Cnum).Value = "hide" Then sh.Columns(Cnum).Hidden = True
Next
Next
End Sub

Right click on the Excel icon next to File in the menubar
And choose View code

You are now in the Thisworkbook module
Paste the Event in this place
Alt-Q to go back to Excel
Save and close the file




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)
www.rondebruin.nl



wrote in message ...
Thanks for the input. The code works great.
However, when I four worksheets in my file and the code
only works for the first worksheet. Even though I have
copied the code into four objects I still get only one
worksheet with the correctly run code. Any thoughts?

-----Original Message-----
I would like to create a macro that, upon opening the
file, looks at each cell in Row two and if that cell has
the term "hide" then the macro will hide that column and
for every column in the range.

Column 1 2 3 4 5 6

row 1 SF LA NY Chi Bos Cle
row 2 hide view hide view view view

Any suggestion on how to code this?

Thank you.
.



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
autoexec macro to run on opening the spreadsheet lee Excel Discussion (Misc queries) 2 January 20th 07 02:01 PM
What does "Compile error in hidden module:Autoexec New" mean? Karla Excel Discussion (Misc queries) 1 September 28th 05 04:47 PM
Autoexec Macro Rick Excel Worksheet Functions 4 August 24th 05 06:15 PM
AutoExec - Enable Macros Bob Barnes[_3_] Excel Programming 3 January 18th 04 07:56 PM
AutoExec George Perchette Excel Programming 1 October 7th 03 11:30 AM


All times are GMT +1. The time now is 04:15 PM.

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

About Us

"It's about Microsoft Excel"