+ Reply to Thread
Results 1 to 7 of 7

Hide/Unhide columns based on value of a cell

  1. #1
    Registered User
    Join Date
    09-23-2011
    Location
    ottawa, ontario
    MS-Off Ver
    Excel 2007
    Posts
    6

    Hide/Unhide columns based on value of a cell

    Hi, I am a newbie at writing macros. I am trying to write a simple macro where I can hide columns based on a value selected from a drop-down list that I have in cell A3.

    For instance if the user selects "NA" then I want columns D:I hidden
    If the user selects "EUROPE" then I want columns B:C and columns F:I hidden
    If the user selects "ASIA PACIFIC" then I want columns B:E hidden.

    How can I accomplish this ? Would appreciate any help.

    Ash
    Last edited by redrackham; 09-24-2011 at 09:13 AM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Hide/Unhide columns based on value of a cell

    hi, redrackham, please check attachment, change A3 cell value. If you delete its value all columns (B:I) become visible
    Attached Files Attached Files

  3. #3
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Hide/Unhide columns based on value of a cell

    Press Alt + F11 on your keyboard, then, in the VBAProject pane, double click the sheet which contains the dropdown. Paste the following code:
    Please Login or Register  to view this content.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  4. #4
    Registered User
    Join Date
    09-23-2011
    Location
    ottawa, ontario
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Hide/Unhide columns based on value of a cell

    Hi Thomas,

    This works great except in one of the options I have to hide two ranges..e.g. when the user selects EUROPE, I need to hide columns B:C and F:I....can I do this using the code you provided ? Thanks so much for your help.

  5. #5
    Registered User
    Join Date
    09-23-2011
    Location
    ottawa, ontario
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Hide/Unhide columns based on value of a cell

    NVM Thomas - I think I got it to work with a minor change to the code you provided. Just one other question...if I wanted to further hide columns based on the value of another cell, A5 where the values will be "PRIMARY", "SECONDARY", "TERTIARY" is this possible ?

  6. #6
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Hide/Unhide columns based on value of a cell

    Sure. Replace the word modify in the code below with the range you want to hide (ie D:I):
    Please Login or Register  to view this content.
    Last edited by tlafferty; 09-23-2011 at 05:15 PM.

  7. #7
    Registered User
    Join Date
    09-23-2011
    Location
    ottawa, ontario
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Hide/Unhide columns based on value of a cell

    Thanks again, Thomas - it worked !

+ 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