VBA code to show/hide rows based on drop down answer

jules_

New Member
Joined
Dec 1, 2016
Messages
4
Hi
I'm fairly new to coding so sorry if this is obvious.
I'm trying to show/hide rows in a workbook based on the answers to another field - drop down with data validation. this what I have so far in the worksheet code but it doesn't seem to work.
row 13 is the row i want to show or hide and E12 has the data validation in it

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E12") = "5k/10k combined" Then
Rows("13:13").EntireRow.Hidden = False
End If
If Range("E12") = "5k" Then
Rows("13:13").EntireRow.Hidden = False
End If
End Sub

help gratefully received

thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Both cases you have:- Hidden = False !!!!
thanks

I have changed it so it now reads
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("E12") = "5k/10k combined" Then
Rows("13:13").EntireRow.Hidden = False
End If
If Range("E12") = "5k" Then
Rows("13:13").EntireRow.Hidden = True
End If
End Sub

but still not working
 
Upvote 0
Make sure you not in "Design Mode"
On the "Ribbon" Click "Developer" tab Then make sure (by Clicking) The "Design Mode" Icon , that it is the same colour as background (Blue)
 
Upvote 0
definitely not in design mode - but good tip.
the code won't let me "step into it" so wondering if that is the issue?
When i press F8 I just get the error bing
 
Upvote 0
Set a "Break Point" by clicking in the margin of the code page, try Line beginning "If Range("E12")--
The see what the code Does.
Maybe the Validation Data does not exactly match the code Data.
NB:- The code worked when I tried it !!
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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