VBA Combo Box hide/unhide cells?

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
409
Does anyone know any VBA code where the option selected from the drop down list (ComboBox) hides/unhides rows.

i.e. If A1 had a ComboBox with a list of 4 names, Name1, Name2, Name3, Name4

if Name 2 is selected row 3 becomes unhidden?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
An advanced version of this is described in two previous threads, see here for details: http://www.mrexcel.com/forum/showthread.php?t=566787

As for your requirement, do you just want one of four hard-coded rows to be visible, and the other 3 hidden?


Code:
Option Explicit
 
Private Sub ComboBox1_Change()
Sheet1.Rows(2).EntireRow.Hidden = True
Sheet1.Rows(3).EntireRow.Hidden = True
Sheet1.Rows(4).EntireRow.Hidden = True
Sheet1.Rows(5).EntireRow.Hidden = True
Select Case ComboBox1.Value
    Case "Name1"
        Sheet1.Rows(2).EntireRow.Hidden = False
    Case "Name2"
        Sheet1.Rows(3).EntireRow.Hidden = False
    Case "Name3"
        Sheet1.Rows(4).EntireRow.Hidden = False
    Case "Name4"
        Sheet1.Rows(5).EntireRow.Hidden = False
        
End Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

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