![]() |
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. |
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. |
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. |
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. . |
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. . |
All times are GMT +1. The time now is 05:09 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com