Making listboxes visible based on the selection of dropdownlist (vba)

Moe12345

New Member
Joined
Jul 14, 2021
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Hi, I am working on a tool I need help with a function of the tool, which I am not quite sure how to apply.
I have dropdown list in cell "E4" with different possible selections. I also have multiple listboxes. What I need help is making them visible based on
what is selected in the dropdown list. That also means that the listboxes shall be hidden or not visible by default and then made to be visible
by the selection.

VBA Code:
'These are options of the dropdown list(cell:"E4"): Sales, Operations, Finance, IT, HR
private Sub ListBox1_Click()
"IT"


End Sub

Private Sub ListBox2_Click()

 "Sales"
End Sub

Private Sub ListBox3_Click()
"Operations"
End Sub

Private Sub ListBox4_Click()
"Finance"
End Sub

Private Sub ListBox5_Click()
"HR"
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I'm assuming that your "Dropdown list" in E4, is a data validation list.
This should work - NB - test on a COPY of your work, first!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Target
   If Intersect(Target, Range("E4")) Is Nothing Then Exit Sub
   
    With Me
        .ListBox1.Visible = False
        .ListBox2.Visible = False
        .ListBox3.Visible = False
        .ListBox4.Visible = False
        .ListBox5.Visible = False
    

        Select Case Target.Value
            Case "Operations"
                .ListBox3.Visible = True
            Case "Sales"
                .ListBox2.Visible = True
            Case "IT"
                .ListBox1.Visible = True
            Case "Finance"
                .ListBox4.Visible = True
            Case "HR"
                .ListBox5.Visible = True
    
        End Select
    End With
End With
... be sure to place it in the worksheet module, of the sheet in question.
 
Upvote 0
Solution
I'm assuming that your "Dropdown list" in E4, is a data validation list.
This should work - NB - test on a COPY of your work, first!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

With Target
   If Intersect(Target, Range("E4")) Is Nothing Then Exit Sub
  
    With Me
        .ListBox1.Visible = False
        .ListBox2.Visible = False
        .ListBox3.Visible = False
        .ListBox4.Visible = False
        .ListBox5.Visible = False
   

        Select Case Target.Value
            Case "Operations"
                .ListBox3.Visible = True
            Case "Sales"
                .ListBox2.Visible = True
            Case "IT"
                .ListBox1.Visible = True
            Case "Finance"
                .ListBox4.Visible = True
            Case "HR"
                .ListBox5.Visible = True
   
        End Select
    End With
End With
... be sure to place it in the worksheet module, of the sheet in question.
this works perfectly, thank you.
 
Upvote 0
You're welcome - glad it worked, and thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,416
Messages
6,119,384
Members
448,889
Latest member
TS_711

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top