+ Reply to Thread
Results 1 to 4 of 4

Hide Columns Based on Condition

  1. #1
    Skornia115
    Guest

    Hide Columns Based on Condition

    New to VBA and need help.

    I am trying to hide columns based on a condition. My workbook has
    numerous worksheets. Each worksheet contains data for a specific
    "account" and each column within the "account" worksheet has month end
    data. Therefore row 1 of each worksheet contains month-end values and
    each row below has various data for that specific "account."
    Furthermore, the first worksheet, which basically serves as a "menu",
    has a cell with a specific date. What I would like to do is write a
    macro in each worksheet representing an "account" that hides all
    columns in the "account" worksheets that have not occurred yet. (i.e.
    If the date on the menu worksheet is 3/31/05, I would like all columns
    that have month-end values exceeding 3/31/05 to be hidden). Any
    suggestions?


  2. #2
    Bob Phillips
    Guest

    Re: Hide Columns Based on Condition


    For Each sh In Activeworkbook.Worksheets
    With sh
    If sh.Name <> "Menu" Then
    For i = 1 To sh.Cells(1,sh.Columns.Count).End(xlUp).Column
    If sh.Cells(1,i).Value >
    Worksheets("Menu").Range("A1").Value Then
    Columns(i).Hidden = True
    End If
    Next i
    End If
    End With
    Next sh

    where A1 on Menu is the menu date comparing against

    --

    HTH

    Bob Phillips

    (replace xxxx in the email address with gmail if mailing direct)

    "Skornia115" <[email protected]> wrote in message
    news:[email protected]...
    > New to VBA and need help.
    >
    > I am trying to hide columns based on a condition. My workbook has
    > numerous worksheets. Each worksheet contains data for a specific
    > "account" and each column within the "account" worksheet has month end
    > data. Therefore row 1 of each worksheet contains month-end values and
    > each row below has various data for that specific "account."
    > Furthermore, the first worksheet, which basically serves as a "menu",
    > has a cell with a specific date. What I would like to do is write a
    > macro in each worksheet representing an "account" that hides all
    > columns in the "account" worksheets that have not occurred yet. (i.e.
    > If the date on the menu worksheet is 3/31/05, I would like all columns
    > that have month-end values exceeding 3/31/05 to be hidden). Any
    > suggestions?
    >




  3. #3
    Skornia115
    Guest

    Re: Hide Columns Based on Condition

    Forgive my for my ignorance but where do I place this syntax?

    Bob Phillips wrote:
    > For Each sh In Activeworkbook.Worksheets
    > With sh
    > If sh.Name <> "Menu" Then
    > For i = 1 To sh.Cells(1,sh.Columns.Count).End(xlUp).Column
    > If sh.Cells(1,i).Value >
    > Worksheets("Menu").Range("A1").Value Then
    > Columns(i).Hidden = True
    > End If
    > Next i
    > End If
    > End With
    > Next sh
    >
    > where A1 on Menu is the menu date comparing against
    >
    > --
    >
    > HTH
    >
    > Bob Phillips
    >
    > (replace xxxx in the email address with gmail if mailing direct)
    >
    > "Skornia115" <[email protected]> wrote in message
    > news:[email protected]...
    > > New to VBA and need help.
    > >
    > > I am trying to hide columns based on a condition. My workbook has
    > > numerous worksheets. Each worksheet contains data for a specific
    > > "account" and each column within the "account" worksheet has month end
    > > data. Therefore row 1 of each worksheet contains month-end values and
    > > each row below has various data for that specific "account."
    > > Furthermore, the first worksheet, which basically serves as a "menu",
    > > has a cell with a specific date. What I would like to do is write a
    > > macro in each worksheet representing an "account" that hides all
    > > columns in the "account" worksheets that have not occurred yet. (i.e.
    > > If the date on the menu worksheet is 3/31/05, I would like all columns
    > > that have month-end values exceeding 3/31/05 to be hidden). Any
    > > suggestions?
    > >



  4. #4
    Skornia115
    Guest

    Re: Hide Columns Based on Condition

    Forgive my for my ignorance but where do I place this syntax?

    Bob Phillips wrote:
    > For Each sh In Activeworkbook.Worksheets
    > With sh
    > If sh.Name <> "Menu" Then
    > For i = 1 To sh.Cells(1,sh.Columns.Count).End(xlUp).Column
    > If sh.Cells(1,i).Value >
    > Worksheets("Menu").Range("A1").Value Then
    > Columns(i).Hidden = True
    > End If
    > Next i
    > End If
    > End With
    > Next sh
    >
    > where A1 on Menu is the menu date comparing against
    >
    > --
    >
    > HTH
    >
    > Bob Phillips
    >
    > (replace xxxx in the email address with gmail if mailing direct)
    >
    > "Skornia115" <[email protected]> wrote in message
    > news:[email protected]...
    > > New to VBA and need help.
    > >
    > > I am trying to hide columns based on a condition. My workbook has
    > > numerous worksheets. Each worksheet contains data for a specific
    > > "account" and each column within the "account" worksheet has month end
    > > data. Therefore row 1 of each worksheet contains month-end values and
    > > each row below has various data for that specific "account."
    > > Furthermore, the first worksheet, which basically serves as a "menu",
    > > has a cell with a specific date. What I would like to do is write a
    > > macro in each worksheet representing an "account" that hides all
    > > columns in the "account" worksheets that have not occurred yet. (i.e.
    > > If the date on the menu worksheet is 3/31/05, I would like all columns
    > > that have month-end values exceeding 3/31/05 to be hidden). Any
    > > suggestions?
    > >



+ 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