LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default hide columns based on header macro

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
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
Hide Columns based on a cell value Tami Excel Worksheet Functions 10 July 16th 09 06:31 PM
Writing a macro to hide columns based on cell value JAbels001 Excel Discussion (Misc queries) 2 April 16th 09 05:02 PM
Automatic Hide group of a columns based on cel value Rechie Excel Discussion (Misc queries) 5 July 16th 08 08:43 PM
Macro to Hide/Show Columns based on control cell value Steve N Excel Programming 2 May 25th 04 06:51 PM
macro to hide column based on header Todd[_6_] Excel Programming 6 September 4th 03 04:34 AM


All times are GMT +1. The time now is 03:03 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"