+ Reply to Thread
Results 1 to 7 of 7

combining hide columns with autofilter rows

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2008
    Location
    England
    Posts
    5

    combining hide columns with autofilter rows

    Hi, I'm new today, so I hope I'm following the rules! (If I've done this incorrectly - sorry - just tell me the right way, please!)

    I have a spreadsheet in Excel 7 for a lifelong cashflow model. The main worksheet is called 'Projection' with ages in rows & income (from a variety of sources) and expenditure (of various kinds) in columns fed with data from the Input sheet.

    On the 'Input' sheet I have a button called Format Graphs which controls the following macro:

    Private Sub CommandButton1_Click()
    Sheets("Projection").Select
        Selection.AutoFilter Field:=1, Criteria1:="<=100", Operator:=xlAnd
        Sheets("Chart Data").Select
        Selection.AutoFilter Field:=1, Criteria1:="<=100", Operator:=xlAnd
        Sheets("Input").Select
    End Sub
    This limits the maximum age to 100.

    On the 'Projection' sheet I have another button called Open All which counteracts the above command and resets the sheet.

    In the Excel Programming forum I thought I'd found the answer in RoyUK's
    ToggleColumns spreadsheet here
    http://www.excelforum.com/excel-prog...de-column.html

    My control row is also 3 and I have amended this so that a column with 1 is to be hidden.

    However, I'm having difficulty in making the is work - Any ideas will be gratefully received.

    The reason for doing this is to produce tidy graphs without orphan legends caused by blank columns.

    If I'm allowed to ask another question here - ideally I would like to link the
    autofilter to cell Input V42 which is where I control the max age for other functions. How can I do this, please?
    Last edited by f1nman; 12-25-2008 at 01:44 PM.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here


    http://www.screencast.com/users/VBAN...a-307763111404

    also will be moved to programming as per forum rules

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Sub HideColumns()
        Dim cell As Range
    
        For Each cell In Intersect(ActiveSheet.UsedRange, Rows(3))
            cell.EntireColumn.Hidden = cell.Value = 1
        Next cell
    End Sub
    Please take a few minutes to read the Forum Rules, and then edit your post to wrap your code with Code Tags.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    12-21-2008
    Location
    England
    Posts
    5
    PHP Code: 
    Private Sub CommandButton1_Click()
    Sheets("Projection").Select
    Selection
    .AutoFilter Field:=1Criteria1:="<=100"Operator:=xlAnd
    Sheets
    ("Chart Data").Select
    Selection
    .AutoFilter Field:=1Criteria1:="<=100"Operator:=xlAnd
    Sheets
    ("Input").Select
    End Sub 
    I hope i've done this correctly

  5. #5
    Registered User
    Join Date
    12-21-2008
    Location
    England
    Posts
    5
    Many thanks, shg, that works.

    If I wanted to restrict the columns to be hidden within a range say, B - BH or two ranges B - Z and AZ - BH how would your code need to be altered?

    James

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Sub HideColumns()
        Dim cell As Range
    
        For Each cell In Intersect(ActiveSheet.UsedRange, Rows(3), _
                                   Union(Range("B:Z"), Range("AZ:BH")))
            cell.EntireColumn.Hidden = cell.Value = 1
        Next cell
    End Sub
    If that works, would you please mark the thread as Solved?


    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

  7. #7
    Registered User
    Join Date
    12-21-2008
    Location
    England
    Posts
    5
    Shg, many thanks - that works!

+ 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