Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub HideColumns()
Dim sh as worksheet Dim c as range For each sh in Worksheets ' loop thru all worksheets For each c in sh.Range("A1:D1") ' assuming this is where your headers are If c.value = Sheets(1).Range("W1").Value Then c.EntireColumn.Hidden=False Else c.EntireColumn.Hidden=True End If Next c Next sh End Sub -- Regards, Tom Ogilvy "Todd" wrote in message ... Thanks so much, I am having an error at "If c.Value = Sheet(1).Range("W1") " which says there is an expected then or go to. I put a then at the end of the statement and I get "sub or function not defined". What else do I need to do? Todd Sub HideColumns() Dim sh As Worksheet Dim c As Range For Each sh In Worksheets ' loop thru all worksheets For Each c In Range("A1:D1") ' assuming this is where your headers are If c.Value = Sheet(1).Range("W1") Then c.EntireColumn.Hidden = False Else c.EntireColumn.Hidden = True End If Next c Next sh End Sub "gocush" wrote: Try something like the following, making adjustments to fit your layout Assume your combobox is on Sheet(1) Attach the following code to your combobox Assign the combobox linkcell as "W1" Sub HideColumns() Dim sh as worksheet Dim c as range For each sh in Worksheets ' loop thru all worksheets For each c in Range("A1:D1") ' assuming this is where your headers are If c.value=Sheet(1).Range("W1") c.EntireColumn.Hidden=False Else c.EntireColumn.Hidden=True End If Next c Next sh End Sub "Todd L." wrote: Hi, I need a macro that can loop through a workbook and based on the headers hide columns. So I could use a dropbox list, select a heading and the headings on the list not selected (four possible headers for the list and 30 worksheets) would be hidden. I learning but am not good at VB and will appreciate any help. Thanks, Todd |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Hide Columns based on a cell value | Excel Worksheet Functions | |||
Writing a macro to hide columns based on cell value | Excel Discussion (Misc queries) | |||
Automatic Hide group of a columns based on cel value | Excel Discussion (Misc queries) | |||
Macro to Hide/Show Columns based on control cell value | Excel Programming | |||
macro to hide column based on header | Excel Programming |