Use VBA to hide / unhide row depending on a selection from a dropdown

Walkie1994

New Member
Joined
Apr 13, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi there,

Im creating a document checklist and i need a row to be hidden until a certain choice is chosen from a dropdown

The dropdown is in B6, and has three choices (England, Scotland, Wales)

If the user selects England, i then need row 14 to appear which will make the user then make another selection,

If the user selects one of the other two options then row 14 can stay hidden,

Ive tried a couple of VBA's from other threads but i cant get them to work (im probably doing something wrong)

Thanks in advance!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "B6" Then
      Rows(14).Hidden = Not Target.Value = "England"
   End If
End Sub
This needs to go in the relevant sheet module.
 
Upvote 0
Solution
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address(0, 0) = "B6" Then
      Rows(14).Hidden = Not Target.Value = "England"
   End If
End Sub
This needs to go in the relevant sheet module.
Thanks for this, i have just tried this but it keeps coming up with compile error: invalid outside procedure when i then go to change one of the options in the drop down in B6
 
Upvote 0
Did you copy & paste the whole code?
 
Upvote 0
Did you copy & paste the whole code?
Hi, Yes i did although i must have done something wrong as it is now working, but it hides the row when England is selected as well as the other two options.
 
Upvote 0
Are you entering England, as opposed to england, or ENGLAND? As VBA is case sensitive.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

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