+ Reply to Thread
Results 1 to 6 of 6

Hidding Columns based on Cell Value

  1. #1
    Registered User
    Join Date
    12-03-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    63

    Hidding Columns based on Cell Value

    Hi Friends,

    I have a drop down with value from 1-20. The cell link is B19. Following is the requirement.

    When cell value of B19 is 1 columns from R:AN should be hidden.
    When cell value of B19 is 2 column R (one column) and AM:AN should be visible
    When cell value of B19 is 3 column R:S ( two column)and AM:AN should be visible
    When cell value of B19 is 4 columns R:T (three column)and AM:AN should be visible.
    .
    .
    .
    When cell value of B19 is 21 columns R:AK (twenty column) and AM:AN should be visible

    New to VBA, but trying to modify the following code and is not working. Kindly advice on the correct code.

    Please Login or Register  to view this content.
    Thanks,
    Rahul

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Hidding Columns based on Cell Value

    1) Copy this code.
    2) Right-Click the sheet tab of interest.
    3) Select "View Code"
    4) Paste the code into the window that appears.
    5) Save the file as a macro-enabled .xlsm file.
    6) Make changes as needed

    Please Login or Register  to view this content.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    12-03-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Hidding Columns based on Cell Value

    Hi Bernie,
    Thanks for your quick reply. I did follow the instructions given by you. But the code does is not working at all. When I change the value from drop down (cell link B19), nothing is happening.

    Thanks,
    Rahul

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,937

    Re: Hidding Columns based on Cell Value

    Sorry, I had assumed that the drop down was a data validation list on cell B19.

    So, the simplest thing is to keep that code and change to Data Validation on B19.

    More complicated is to create a formula in another cell using the formula

    =B19

    and use this code instead of what I had originally posted.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-03-2013
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Hidding Columns based on Cell Value

    Thanks so much Bernie. The code is working now

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,860

    Re: Hidding Columns based on Cell Value

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

+ 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. Protection sheets disables VBA hidding columns?
    By horsefish01 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 06-21-2015, 01:53 PM
  2. Hidding/Unhidding Worksheets Based on User Selection
    By Basia22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-09-2014, 01:27 PM
  3. [SOLVED] Un/Hidding Cells based upon drop down list
    By Kramxel in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2012, 03:41 AM
  4. Hidding Unused Rows based on column value
    By mashley in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2010, 01:51 PM
  5. [SOLVED] Hidding columns not working
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2005, 06:20 PM
  6. Hidding columns not working
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-02-2005, 06:17 PM
  7. Hidding Columns depending on cell value
    By oakman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-21-2005, 11:31 AM

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