+ 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
    Last edited by KristofferA; 11-28-2014 at 10:36 AM.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,055

    Re: Show and hide columns after filtering

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Never use Merged Cells in Excel

  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

    Oops! Sorry. All sorted now

+ 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 / Hide columns
    By DBenson1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2014, 05:27 PM
  2. 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
  3. Excel 2008 : Hide/show columns
    By Didieeer in forum Excel General
    Replies: 1
    Last Post: 02-02-2012, 07:36 AM
  4. Hide Show columns
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2007, 06:10 AM
  5. [SOLVED] Show/Hide Columns
    By StephanieH in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-24-2005, 10:05 AM

Tags for this Thread

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