+ Reply to Thread
Results 1 to 8 of 8

Macro to hide columns based on Table Headers

  1. #1
    Forum Contributor
    Join Date
    06-19-2012
    Location
    Canada
    MS-Off Ver
    Mac Office 365
    Posts
    171

    Macro to hide columns based on Table Headers

    I have a spreadsheet I use to track costs at various stores that I have set up with macros so I can just pick the store I am currently at and see that info only. It is a work in progress, and I want to add some new columns in it for more info. Doing that of course 'breaks' the current macros and then hides the wrong columns.

    I need help updating my existing macros to hide based on table headers, not the column itself.
    (Note - I only need one sample to go off of, I won't need all of my 'hide' macros updated.)

    Please Login or Register  to view this content.
    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,033

    Re: Macro to hide columns based on Table Headers

    Add this to the top of your Module1 code, above all of the other subs.
    Please Login or Register  to view this content.
    Add this to a standard module. Can be in the Module1.
    Please Login or Register  to view this content.
    Your store specific subs would then look like this.
    Please Login or Register  to view this content.
    See Attached.

    Does that work for you?

    BSB
    Attached Files Attached Files
    Last edited by BadlySpelledBuoy; 05-29-2025 at 03:15 PM.

  3. #3
    Forum Contributor
    Join Date
    10-16-2023
    Location
    Poland
    MS-Off Ver
    Excel 2019 32bit WIN10
    Posts
    142

    Re: Macro to hide columns based on Table Headers

    My suggestion:
    Please Login or Register  to view this content.
    Assign this macro to each shape. The procedure will find columns according to the shape caption.

  4. #4
    Forum Contributor
    Join Date
    06-19-2012
    Location
    Canada
    MS-Off Ver
    Mac Office 365
    Posts
    171

    Re: Macro to hide columns based on Table Headers

    @ BadlySpelledBuoy Thank you, this is absolutely perfect; does exactly what I want when adding columns. So much more advanced and simpler

    I did also add a couple more columns at the begining that I don't want hidden though; can you tell me how to modify it so that the first 4 columns stay open? I tried a couple things I thought might be right, but I just broke it

    Please Login or Register  to view this content.

    New workbook sample attached.

    @ Tajan, I will check your solution out tomorrow... thank you!
    Attached Files Attached Files
    Last edited by Tamarissa; 05-29-2025 at 10:43 PM.

  5. #5
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,033

    Re: Macro to hide columns based on Table Headers

    Change the 2 in this line for the number of the first column that could be hidden.
    Please Login or Register  to view this content.
    So if the first column with a store name is E, it should be this
    Please Login or Register  to view this content.
    BSB

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,038

    Re: Macro to hide columns based on Table Headers

    Another Option...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  7. #7
    Forum Contributor
    Join Date
    06-19-2012
    Location
    Canada
    MS-Off Ver
    Mac Office 365
    Posts
    171

    Re: Macro to hide columns based on Table Headers

    @BadlySpelledBuoy Thank you teaching me how to modify it correctly, I appreciate it!

    @Tajan This macro also works beautifully, so thank you for you input

  8. #8
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    8,033

    Re: Macro to hide columns based on Table Headers

    Glad we could help

    BSB

+ 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/Unhide lies with 0 based on 3 columns - looking to exclude from running on headers
    By thebluejoker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-12-2024, 10:17 AM
  2. [SOLVED] VBA to hide Multiple Columns based on Headers
    By FvdF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-01-2020, 02:46 PM
  3. [SOLVED] Hide same columns that were hidden for the other headers
    By luajambeiro in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-19-2019, 10:57 AM
  4. [SOLVED] Hide all columns except those with certain headers/titles
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-31-2014, 08:32 AM
  5. [SOLVED] Hide columns based on dynamic headers
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2013, 03:21 AM
  6. Excel 2007 : Macro to copy columns based headers
    By rls1316 in forum Excel General
    Replies: 2
    Last Post: 04-25-2011, 10:22 PM
  7. Macro to Sum Columns based on Headers
    By Jluc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2011, 02:36 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