+ Reply to Thread
Results 1 to 8 of 8

Hide columns if rows empty

  1. #1
    Registered User
    Join Date
    01-24-2012
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    4

    Hide columns if rows empty

    Hi everyone,

    I've attached a worksheet that has buttons to hide/unhide columns. Currently the 'hide' button has a very basic macro tied to it, but I need the macro to be enhanced so that it will just hide any columns between A-CA that are blank in row 6 or below. This will allow the form to become a manageable size for printing.

    I'd appreciate any assistance, thank you!
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro help - hide columns if rows empty

    Hello Melewis212,

    Welcome to the Forum!

    Here is the updated macro to hide the columns.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    01-24-2012
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide columns if rows empty

    Thank you Leith Ross! When I tested the macro and it hid columns that had alpha characters, I think its only hiding a column if the sum of all its rows is 0. Is there a way to tweak it to hide columns that don't have alpha or numeric characters in row 6 or below?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Hide columns if rows empty

    Hello melewis212,

    Columns are vertical and rows are horizontal. When hiding either a column or row, all associated data is hidden. It is either an all or nothing function. How do you want the page to appear?

  5. #5
    Registered User
    Join Date
    01-24-2012
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide columns if rows empty

    For example, in column A/row 6 I have "AA" populated and in column B/row 6 I have "10" populated. In this scenario, I would want columns C-CA to be hidden since they are blank in row 6 and below. I would just want to see column A and B. However, currently column A as well as columns C-CA are being hidden.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Hide columns if rows empty

    Hello melewis212,

    The version of the macro does what you want. It looks only at the values starting in row 6 down to the last row with data. No formulas nor validation objects are counted. If all the cells in the column are empty then the column is hidden.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-24-2012
    Location
    Tampa, Florida
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Hide columns if rows empty

    Hi Leith Ross,

    Thank you for the new macro. I tried it out, but I'm getting this error "runtime error 424 object required". Debugging indicated it's this part of the code: 'For Each Item In Data.Value'.

    I really appreciate your help!

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Hide columns if rows empty

    Hello melewis212,

    Sorry, the .Value is a typing error. Remove it and it should run without problem.

+ 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