+ Reply to Thread
Results 1 to 5 of 5

Automatically hide empty columns from Filtered Table based on Totals Row

  1. #1
    Registered User
    Join Date
    02-13-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    4

    Automatically hide empty columns from Filtered Table based on Totals Row

    Hello,

    I am very new to VBA so I can't work out a way to do the following:

    I have an Excel Table with multiple Rows and Columns. What I would like to be able to do is, after applying a Filter on the table, all columns which have only 0 or empty cells to become automatically hidden.

    I thought that perhaps an easy solution would be to first to use the Count function on the Totals Row of the Table. Therefore, if after applying a filter, all the cells were 0 or empty the Totals Row would be equal to zero too since this function is dynamic and changes after applying a filter.

    VBA could check the value on the Totals Row of the table using ActiveSheet.ListObjects("Table1").TotalsRowRange.Select and if the cell is equal to 0 after applying the filter then it would hide the respective column using the function .EntireRow.Hidden = True .

    Unfortunately, I don't know how to write this down as a VBA module. I 'd appreciate any help.

    Hide Empty Columns.xlsx

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Automatically hide empty columns from Filtered Table based on Totals Row

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Automatically hide empty columns from Filtered Table based on Totals Row

    I should have refreshed before posting.
    John has provided a solution.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  4. #4
    Registered User
    Join Date
    02-13-2015
    Location
    London
    MS-Off Ver
    2010
    Posts
    4

    Post Re: Automatically hide empty columns from Filtered Table based on Totals Row

    Thank you for your post John. It works and only needs a tweak to make the columns unhide once you change the filter because otherwise you will end up with less columns showing.

    A colleague just offered also this solution which works perfectly.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Automatically hide empty columns from Filtered Table based on Totals Row

    You're welcome. Glad you found a working solution.

+ 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. Hide Columns automatically based on date
    By ravisidhu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2015, 01:15 AM
  2. VBA code to hide filtered columns (simple table 5 rows / 6 columns wide)
    By e2010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2014, 02:41 PM
  3. Replies: 3
    Last Post: 11-04-2013, 07:50 PM
  4. Automatically Hide/Unhide Columns Based Dropdown List
    By Kapil.gour in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-27-2012, 07:39 AM
  5. Hide Columns automatically based on date
    By chrisjc19 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-06-2011, 03:32 PM
  6. How do I automatically hide columns in a worksheet based on a cell value?
    By dkhedkar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-04-2005, 09:06 PM
  7. Replies: 0
    Last Post: 03-04-2005, 02:43 PM

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