+ Reply to Thread
Results 1 to 4 of 4

Hide/unhide columns based on a dropdown list (or tick list if it's possible)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2016
    Location
    Sandefjord, Norway
    MS-Off Ver
    Office 365 Business
    Posts
    30

    Hide/unhide columns based on a dropdown list (or tick list if it's possible)

    Hi,

    I have an Excel-sheet that I wish to hide/unhide columns based on a dropdown list (or multiple tick list if it's possible).

    The dropdown list should look like this:
    • 1-1 to 1-6
    • 1-7 Progress check
    • 2-1 to 2-6
    • 2-7 Progress check
    • 3-1 to 3-2
    • 3-3 to 3-5
    • 3-6 Progress check
    • 3-7 to 3-9
    • 3-10 to 3-20
    • 3-21
    • 3-22 to 3-23
    • 4-1 to 4-3
    • 4-4 to 4-10
    • 4-11 Progress check
    • 4-12 to 4-22
    • 4-23 Progress check
    • 4-24 to 4-28
    • 4-29 Progress check
    • 4-30 to 4-32
    • 4-33 to 4-37
    • 4-38 to 4-43
    • 4-44 Progress check
    • 5-1 to 5-9
    • Skill test & Proficiency check MEP IR
    • Skill test & Proficiency check SEP
    • Assessment of Competence FI

    I want 1-1 to 1-6 to show columns C:D:E:G:O:R:V:X:Y:Z:AC:AD:AK:AL:AN:AX:BA
    I want 1-7 Progress check to show columns C:D:E:G:O:R:V:X:Y:Z:AC:AD:AK:AL:AN:AP:AX:BA

    The rest I will probably figure out as soon as I see the coding on the first two.

    See the attached file for the layout.

    Thanks in advance!
    Attached Files Attached Files
    Last edited by joherszch; 06-23-2020 at 11:28 AM. Reason: Solved

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

    Re: Hide/unhide columns based on a dropdown list (or tick list if it's possible)

    The attached macro-enabled file has DV with your list on cells in column B, and this code in the sheet's codemodule - just in case I selected the wrong range to apply the code to.

    Note that when you want to show adjacent columns, you can use FirstColumn:LastColumn, and when you want a single column you need Column:Column, like

    AK:AL,AN:AN

    Note too that VBA is case sensitive, so make sure your code uses exactly what is in the list of values.

    '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
    
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("B2:B73")) Is Nothing Then Exit Sub
        If Target.Cells.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        
        Range("C:BB").EntireColumn.Hidden = True
        
        Select Case Target.Value
        Case "1-1 to 1-6"
        Range("C:E,G:G,O:O,R:R,V:V,X:Z,AC:AD,AK:AL,AN:AN,AX:AX,BA:BA").EntireColumn.Hidden = False   'C:D:E:G:O:R:V:X:Y:Z:AC:AD:AK:AL:AN:AX:BA
        Case "1-7 Progress check"
        Range("C:E,G:G,O:O,R:R,V:V,X:Z,AC:AD,AK:AL,AN:AN,AP:AP,AX:AX,BA:BA").EntireColumn.Hidden = False 'C:D:E:G:O:R:V:X:Y:Z:AC:AD:AK:AL:AN:AP:AX:BA
        End Select
    End Sub
    Attached Files Attached Files
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    08-02-2016
    Location
    Sandefjord, Norway
    MS-Off Ver
    Office 365 Business
    Posts
    30

    Re: Hide/unhide columns based on a dropdown list (or tick list if it's possible)

    Thank you very much! Exactly like I wanted it to be :D

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

    Re: Hide/unhide columns based on a dropdown list (or tick list if it's possible)

    Great - thanks for letting me know that it works - and good luck adding your code for the rest!

+ 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. problem of hide/unhide columns based on drop down list
    By rachelhe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2019, 03:15 AM
  2. Unhide Period Columns based on Dropdown list
    By Barieq in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2016, 03:57 PM
  3. [SOLVED] Unhide Period Columns based on Dropdown list
    By Barieq in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-24-2016, 10:17 AM
  4. Hide/Unhide rows based on Yes or No answers to questions by dropdown list.
    By Johny1 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 02-12-2015, 06:57 PM
  5. hide/unhide columns based on dropdown list.
    By bg781np in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-18-2013, 07:13 PM
  6. 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
  7. 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

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