Forum Discussion
mzeller1776
Jan 29, 2026Brass Contributor
Hide rows based on Drop-down box selection
Hello, I have a drop-down box with different selections. One of which is "VPN to VPN Cloud-Based". If this is selected then I want to hide rows 36 through 239. Doing something wrong in my code, as i...
- Feb 04, 2026
I was able to get this to work by using the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$O$35" Then
Select Case Target.Value
Case "VPN to VPN Cloud-Based"
Rows("36:239").EntireRow.Hidden = True
Case "Please Select"
Rows("36:239").EntireRow.Hidden = False
Case "Leased Line"
Rows("36:239").EntireRow.Hidden = False
Case "Custom Network"
Rows("36:239").EntireRow.Hidden = False
Case "N/A"
Rows("36:239").EntireRow.Hidden = False
Case "Please Select:"
Rows("36:239").EntireRow.Hidden = False
End Select
End If
End Sub
VBasic2008
Feb 04, 2026Brass Contributor
Hide Rows Based on Dropdown using Worksheet Change
It seems to me that you can simplify your code with
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$O$35" Then
Rows("36:239").Hidden = (Target.Value = "VPN to VPN Cloud-Based")
End If
End Subwhich is short for
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$O$35" Then
If Target.Value = "VPN to VPN Cloud-Based" Then
Rows("36:239").Hidden = True
Else
Rows("36:239").Hidden = False
End If
End If
End SubIf you plan to add more 'true' cases, you could use
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$O$35" Then
Select Case Target.Value
Case "VPN to VPN Cloud-Based" ' more cases here
Rows("36:239").Hidden = True
Case "Please Select", "Leased Line", "Custom Network", "N/A", _
"Please Select:" ' , "" ' ???
Rows("36:239").Hidden = False
Case Else ' what about any other cases, e.g. "" (vbNullString)???
Rows("36:239").Hidden = False ' ???
End Select
End If
End SubRather use the Else case instead of the 2nd case.