View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
gocush[_28_] gocush[_28_] is offline
external usenet poster
 
Posts: 42
Default hide columns based on header macro

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