VBA to Hide Rows Based on Cell Value.

LauraEdson10

New Member
Joined
Apr 10, 2018
Messages
21
Office Version
  1. 365
Platform
  1. Windows
I have a dropdown box in Cell A17 which is a list to give me the options of either "Yes" or "No".

If I select "No", rows 18:22 need to be hidden. If I select "Yes", rows 18:22 need to show.

Can anyone help me with the VBA formula please?

My sheet name is "Invoicing Instructions" if you needed to know.

Thank you.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
I have a dropdown box in Cell A17 which is a list to give me the options of either "Yes" or "No".

If I select "No", rows 18:22 need to be hidden. If I select "Yes", rows 18:22 need to show.

Can anyone help me with the VBA formula please?

My sheet name is "Invoicing Instructions" if you needed to know.

Thank you.
Tbh there are many threads like these. even today there was one asking for the same but then with columns. might wanna look at that?
https://www.mrexcel.com/forum/excel...-unhide-columns-based-dropdown-selection.html
However in your case you dont need bigger or smaller than. its just a simple If range("A17") = "Yes" Then
Else
situation
Code:
[COLOR=#333333]            If Range("A17") = "Yes" Then .Range("18:22").Rows.Hidden = False Else .Range("18:22").Rows.Hidden = True[/COLOR]
 
Last edited:
Upvote 0
I did see ones similar but theirs are based on a numerical cell value rather than text and mostly based upon multiple criteria so I couldn't figure out how to tailor the formula to suit :confused:
 
Upvote 0
look reply #2 i editted it. that should work what you want. if you want i can add the sub and stuff in.
 
Upvote 0
Code:
Sub Hidden()
Dim cel As Range
Dim rng1 As Range
Set rng1 = Range("18:22")
Set cel = Range("A17")
    If cel = "Yes" Then
        rng1.rows.Hidden = False
    Else
        rng1.rows.Hidden = True
    End If
End Sub
This works
 
Last edited:
Upvote 0
It doesn't seem to be working, nothing happens?
It sure works for me. Are you sure you right click on your sheet and pressed view code and pasted it in? now u need a button to activate it. or press F5 if ur in the script.
 
Upvote 0
It sure works for me. Are you sure you right click on your sheet and pressed view code and pasted it in? now u need a button to activate it. or press F5 if ur in the script.

Yeah, it's entered in exactly as you wrote. I press F5 and change from "Yes" to "No" and visavera, nothing happens :(
 
Upvote 0
It's sort of working. If you press "No", then the box disappears. However, if you click "Yes" again, it just stays hidden?

Also, you have to press F5 within View Code everytime, it needs to be automatic.
 
Last edited:
Upvote 0
Yeah, it's entered in exactly as you wrote. I press F5 and change from "Yes" to "No" and visavera, nothing happens :(
Hmm thats weird it works for me if i try it myself. Can you perhaps show me a screenshot of your worksheet?
If its "No" then the 4 rows will hide if its "Yes" they will just be there for everyone to watch.
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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