Forum Discussion

mzeller1776's avatar
mzeller1776
Brass Contributor
Jan 29, 2026
Solved

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 it isn't doing anything when "VPN to VPN Cloud-Based" is select. Any ideas what I need to change? Attaching screenshot of the form and the VBA. Thanks. 

  • 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

3 Replies

  • VBasic2008's avatar
    VBasic2008
    Brass 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 Sub

    which 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 Sub

    If 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 Sub

    Rather use the Else case instead of the 2nd case.

     

  • mzeller1776's avatar
    mzeller1776
    Brass Contributor

    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

  • NikolinoDE's avatar
    NikolinoDE
    Platinum Contributor

    Could you please share:

    Your current VBA code (you can paste it as text)

    Details about your dropdown:

    Is it a Data Validation dropdown or an ActiveX/Form Control?

    Which cell contains the dropdown?

    What's the exact text of the selection options?

    Additional: Which operating system?

    Which Office version?

    In this link you will find some more information about it:

    Welcome to your Excel discussion space!

    So no one needs to guess and exclude many ways/causes with a lot of communicative time.

     

    Thank you for your understanding and patience

     

    NikolinoDE

    I know I don't know anything (Socrates)