Results 1 to 5 of 5

"VBA code to hide/show rows based on multiple selection of drop down list.

Threaded View

  1. #1
    Registered User
    Join Date
    01-09-2020
    Location
    Canada
    MS-Off Ver
    Excel Version 1912 (Build 12325.20344 Microsoft Store)
    Posts
    36

    "VBA code to hide/show rows based on multiple selection of drop down list.

    Hi All,

    Relatively new to VBA stuff in Excel, kind of have things figured out but this is beyond what I can figure out. In short, I currently have a code that will "hide/show" lines/columns based on a cell selection made. Works great (thanks to the folks that helped me tweak that that). If a cell value is "yes", then it shows the rows, if a cell value is "no" then it keeps the rows hidden. What I am trying to accomplish now is if there is a way to "rewrite" the code based on multiple list values (no repetition). Example: User can choose multiple items from a drop down list of values at the same time, example: multiple list could have values to select of "Select One", "None", "1", "2", "3", "4", "5". They can select as many items from the list that they need. IE: If the default is "Select One" then no rows show, If "None" is selected then again no rows will show. If they select only "1" from the multiple list values then row 10 will show. If they select "1, 3, 5" from the multiple list value then rows 10, 12 and 14 will show. If possible I also need to set it up so that if "Select One" or "None" are selected along with "1" (or any other value in the list) that it still has the rows hidden so there isn't an "error". Any help would be greatly appreciated. (as a side note, I am hoping that I can add "multiple" drop down lists on the same sheet that will do the same thing. IE: second drop down list could have apple, banana, orange etc. and it too would show rows 18, 24, 46 (as an example) on the same sheet based on those different ranges/selections. ))

    Hope that makes sense. Thanks in advance to all.

    Current code is below (yes there is a lot of lines that I need to hide/show...not fun on my end but if I can get it to work with one "range" I should be able to duplicate it over the ranges that I need )


    [code]


    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim KeyCells As Range
    
        Set KeyCells = Range("J5,J23,J33,J42,H55,E62,E70,J4")
        
        If Not Application.Intersect(KeyCells, Range(Target.Address)) _
            Is Nothing Then
    
            If Range("J5") = "Yes" Then
                Rows("8:20").EntireRow.Hidden = False
            End If
            If Range("J5") = "No" Or Range("J5") = "-Select One-" Then
                Rows("8:20").EntireRow.Hidden = True
                
           End If
           If Range("J23") = "Yes" Then
                Rows("25:30").EntireRow.Hidden = False
                
           End If
           If Range("J23") = "No" Or Range("J23") = "-Select One-" Then
                Rows("25:30").EntireRow.Hidden = True
                
           End If
           If Range("J33") = "Yes" Then
                Rows("35:39").EntireRow.Hidden = False
                
           End If
           If Range("J33") = "No" Or Range("J33") = "-Select One-" Then
                Rows("35:39").EntireRow.Hidden = True
                
           End If
           If Range("J42") = "Yes" Then
                Rows("44:52").EntireRow.Hidden = False
                
           End If
           If Range("J42") = "No" Or Range("J42") = "-Select One-" Then
                Rows("44:52").EntireRow.Hidden = True
                
           End If
           
           If Range("H55") = "Ok" Then
                Rows("57:76").EntireRow.Hidden = False
                
                          
           End If
           If Range("H55") = "-Select Ok-" Then
                Rows("57:76").EntireRow.Hidden = True
                
           End If
           If Range("E62") = "Yes" Then
                Rows("63:68").EntireRow.Hidden = False
                
           End If
           If Range("E62") = "No" Or Range("E62") = "-Select One-" Then
                Rows("63:68").EntireRow.Hidden = True
                
           End If
           If Range("E70") = "Yes" Then
                Rows("71:75").EntireRow.Hidden = False
               
           End If
           If Range("E70") = "No" Or Range("E70") = "-Select One-" Then
                Rows("71:75").EntireRow.Hidden = True
                
           End If
           End If
           If Range("J4") = "Show" Then
                Columns("K:N").EntireColumn.Hidden = False
               
           End If
           If Range("J4") = "Hide" Then
                Columns("K:N").EntireColumn.Hidden = True
           
        
           
        End If
        
    End Sub
    [code]
    Last edited by Pepe Le Mokko; 02-02-2020 at 04:41 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Hide Multiple Rows Based on Drop Down Menu Selection
    By leebird in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-16-2018, 07:52 AM
  2. Hide Multiple Rows Based on Drop Down Menu Selection
    By leebird in forum Excel General
    Replies: 1
    Last Post: 02-16-2018, 03:28 AM
  3. [SOLVED] Hide/Show rows based on drop down list
    By PvtJoker in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-13-2017, 04:11 PM
  4. Replies: 1
    Last Post: 06-25-2015, 07:29 AM
  5. Macro to hide/show rows based on Drop Down selection
    By Bleucherie in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-03-2015, 06:14 PM
  6. Hide-Unhide rows on multiple worksheets based on value of a drop down list
    By clo2peter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-10-2014, 08:32 AM
  7. [SOLVED] VBA code to hide/unlide rows based on drop down list
    By evakotsi in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 10:30 PM

Tags for this Thread

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