+ Reply to Thread
Results 1 to 4 of 4

Hide Column Condition

  1. #1
    al007
    Guest

    Hide Column Condition

    Can anybody give me a macro for the following:

    I have a list of item on row 2, with their corresponding category on
    row 1 as per below:

    Categ A CategB Categ A Gateg C Categ A Categ B
    Item1 Item2 Item3 Item4 Item5 Item6

    I would like to hide all column if categories in row 1 are not of
    Category A

    Thxs beforehand


  2. #2
    Rowan Drummond
    Guest

    Re: Hide Column Condition

    Try:

    Sub header()
    Dim eCol As Integer
    Dim i As Integer
    eCol = Cells(1, Columns.Count).End(xlToLeft).Column
    For i = 1 To eCol
    With Cells(1, i)
    If .Value <> "Categ A" Then
    .EntireColumn.Hidden = True
    End If
    End With
    Next i
    End Sub

    Hope this helps
    Rowan

    al007 wrote:
    > Can anybody give me a macro for the following:
    >
    > I have a list of item on row 2, with their corresponding category on
    > row 1 as per below:
    >
    > Categ A CategB Categ A Gateg C Categ A Categ B
    > Item1 Item2 Item3 Item4 Item5 Item6
    >
    > I would like to hide all column if categories in row 1 are not of
    > Category A
    >
    > Thxs beforehand
    >


  3. #3
    al007
    Guest

    Re: Hide Column Condition

    Thxs a lot !! - One last favor - how can I make it work for
    Sheet1,Sheet2 & Sheet3 with one same macro

    Thxs
    Rowan Drummond wrote:
    > Try:
    >
    > Sub header()
    > Dim eCol As Integer
    > Dim i As Integer
    > eCol = Cells(1, Columns.Count).End(xlToLeft).Column
    > For i = 1 To eCol
    > With Cells(1, i)
    > If .Value <> "Categ A" Then
    > .EntireColumn.Hidden = True
    > End If
    > End With
    > Next i
    > End Sub
    >
    > Hope this helps
    > Rowan
    >
    > al007 wrote:
    > > Can anybody give me a macro for the following:
    > >
    > > I have a list of item on row 2, with their corresponding category on
    > > row 1 as per below:
    > >
    > > Categ A CategB Categ A Gateg C Categ A Categ B
    > > Item1 Item2 Item3 Item4 Item5 Item6
    > >
    > > I would like to hide all column if categories in row 1 are not of
    > > Category A
    > >
    > > Thxs beforehand
    > >



  4. #4
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Enclose the main body of Rowan's code with a For...Next Loop:

    For each sh in Worksheets
    Sh.Activate

    Code

    Next

    David

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1