+ Reply to Thread
Results 1 to 3 of 3

Show and hide columns after filtering

Hybrid View

  1. #1
    Registered User
    Join Date
    11-25-2014
    Location
    Swindon, England
    MS-Off Ver
    2013
    Posts
    30

    Show and hide columns after filtering

    Hi folks.

    Having trouble with this issue and need some advice/direction.

    Attached is a spreadsheet showing an example task breakdown.
    I'm looking to be able to filter out the task elements, and then hide the columns which have just had the filter applied.

    I'm looking to create a macro for each of the buttons on the screen which goes into the auto filter on the task elements column and selects only blanks (thus hiding any record of a task element) and then hiding that column once the filter has been applied.


    I've managed to record a macro of the opposite action, however when I record the aforementioned action, it hides all columns with information in it.
    Below are both VBA scripts for reference:
    Sub Hide_TE()
    '
    ' Hide_TE Macro
    '
    
    '
        ActiveSheet.Range("$A$2:$C$18").AutoFilter Field:=3, Criteria1:="="
        Columns("C:C").Select
        Range("C2").Activate
        Selection.EntireColumn.Hidden = True
    End Sub
    
    Sub Show_TE()
    '
    ' Show_TE Macro
    '
    
    '
        Columns("B:D").Select
        Range("D2").Activate
        Selection.EntireColumn.Hidden = False
        ActiveSheet.Range("$A$2:$C$18").AutoFilter Field:=3
        Range("A1:F1").Select
    End Sub
    Any help on this would be greatly appreciated. In my real working document it is not only column C that I need to hide. There may be many columns of task elements so a bit of direction in how to edit the code to apply to other sheets would be great.

    Thanks a lot Tea Making WBS.xlsx

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Show and hide columns after filtering

    Remove this line
        Range("C2").Activate
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    11-25-2014
    Location
    Swindon, England
    MS-Off Ver
    2013
    Posts
    30

    Re: Show and hide columns after filtering

    Unfortunately that doesn't seem to work.
    Columns A to F just end up hidden as before.
    As explained earlier the "Show_TE" macro works fine, just the reverse of it doesn't work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Show and hide columns after filtering
    By KristofferA in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2014, 10:37 AM
  2. Show / Hide columns
    By DBenson1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2014, 05:27 PM
  3. How to hide columns if value is zero -- after filtering data
    By sirronstuff in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-21-2013, 03:50 PM
  4. Excel 2008 : Hide/show columns
    By Didieeer in forum Excel General
    Replies: 1
    Last Post: 02-02-2012, 07:36 AM
  5. Hide Show columns
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2007, 06:10 AM

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