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]
Bookmarks