+ Reply to Thread
Results 1 to 6 of 6

hide/unhide columns based on dropdown list.

  1. #1
    Registered User
    Join Date
    10-18-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    hide/unhide columns based on dropdown list.

    Hi All,

    I am new to using macros. When I say new, I’m talking in the past 2 weeks, so any help would be great.

    I have Microsoft Excel 2010, and I have created a spread sheet with 17 columns (A – R) and 95 rows. In the entire column D, there is a dropdown list that I created using Data Validation. It lists down the words Yes, No and call back.

    What I need is when you click in any cell in column D, and choose either No or Call Back from the drop down list, that columns E trough to K will be hidden, and when you choose Yes from the drop down list these columns will be unhidden. Also how can I protect and unprotect using code?

    Can you please help? I tried many times but not successful. Appreciate if someone will be able to walk me through how to do this. Thanks a lot. Nephi.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: hide/unhide columns based on dropdown list.

    The macro you need is sheet specific and runs whenever you change the sheet,

    The macro checks to see if the cell that was changed was in column D.

    If so the macro then reads the cell and modifies your spreadsheet.

    If you had included a sample I'd know how to help you further.

    How did you create a drop down list in the whole of column D.

    why not on the top row and freeze the window?
    Last edited by mehmetcik; 10-18-2013 at 03:47 PM.

  3. #3
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: hide/unhide columns based on dropdown list.

    Hi Nephi,

    I'm not sure I understand what you mean about the result of hiding columns for rows where the D cell in a row contains either No or Call Back. You could hide the rows where D contains those values but not just some of the cells on those rows, which doesn't sound like what you want to happen. I think you may want to rethink how this workbook is going to be used.

    Here's an example of hiding specific columns, which also contains the commands to unprotect and protect a sheet.

    Please Login or Register  to view this content.
    Then unhide them.

    Please Login or Register  to view this content.
    Also note the Application.ScreenUpdating = True or False. This will eliminate any screen flicker or any movement at all that might be visible while the macro runs.

    I'm afraid I don't know how to get these macros to react to a selection of the DV Lists though. I would just use buttons and assign the macros to them, running them when needed.
    -------------
    Tony

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: hide/unhide columns based on dropdown list.

    I have created something to get you started.

    change col d and columns get hidden
    change column d again and columns get un hidden.

    right click on the sheet name and select view code to see the macro.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-18-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: hide/unhide columns based on dropdown list.

    Hi Guys,

    Thank you for trying to help, I'm sorry if I was not very clear as I said I'm new at this. Attached is the spreadsheet I'm working with.

    In each cell of column D, there is a dropdown list that I created using Data Validation. It gives the user the options of picking from the list of Yes, No and call Back.

    What I need is when you click in any cell in column D, and choose either No or Call Back from the drop down list, that columns E trough to K will be hidden, and when you choose Yes from the drop down list these columns will be unhidden. Also how can I protect and unprotect using code?

    I hope that this might be a lttle clearer especially with the attached spreadsheet. Cheers Nephi.
    Attached Files Attached Files

  6. #6
    Forum Contributor BeachRock's Avatar
    Join Date
    11-01-2011
    Location
    Oregon, United States
    MS-Off Ver
    Excel 2016
    Posts
    403

    Re: hide/unhide columns based on dropdown list.

    Hi Nephi,

    You can't only hide the cells adjacent to the row you are on (E through K) without hiding the entire column for all rows on the sheet. Maybe some conditional formatting would better suit your needs? You could then cause the info for those columns on each row to change colors or fonts or whatever when Yes or No or Call Back is selected in column D on whichever row you are on at the time.

+ 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. 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
  2. Hide/unhide columns based on the drop down list value
    By vagif in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-16-2012, 02:13 AM
  3. Hide/Unhide rows Based on Value from Dropdown Lists
    By 2Deep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2010, 09:43 PM
  4. Hide & Unhide columns based on a cell value
    By DaveNUFC in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-21-2010, 09:40 AM
  5. Unhide/Hide column when choosing dropdown list
    By yuzi in forum Excel General
    Replies: 4
    Last Post: 10-06-2009, 12:44 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