first time vba-er seeking hide/unhide help

sonyaeb

New Member
Joined
Jul 1, 2014
Messages
6
I'm creating a brief doc and I have most of the "if this, then thats" but one section won't unhide cells - ref. B26.
The code above and below is working (ref. B23 & B39) - I have tried the bulk code as shown below and separated, but neither seem to work. Ideally, I would prefer that the code was shortened but I don't know the commands. Thank you in advance to anyone who can help!!

If Range("B23").Value = "N" Then
Rows("24").EntireRow.Hidden = True
ElseIf Range("B23").Value = "Y | N" Then
Rows("24").EntireRow.Hidden = True
ElseIf Range("B23").Value = "Y" Then
Rows("24").EntireRow.Hidden = False
End If

If Range("B26").Value = "Choose" Then
Rows("27:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_1UP_LFT" Then
Rows("29:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_1UP_LFT" Then
Rows("27:28").EntireRow.Hidden = False
ElseIf Range("B26").Value = "PROD_ROW1_1UP_LFT_RATING" Then
Rows("29:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_1UP_LFT_RATING" Then
Rows("27:28").EntireRow.Hidden = False
ElseIf Range("B26").Value = "PROD_ROW1_1UP_RT_RATING" Then
Rows("29:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_1UP_RT_RATING" Then
Rows("27:28").EntireRow.Hidden = False
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("27:28").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("33:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("29:32").EntireRow.Hidden = False
ElseIf Range("B26").Value = "PROD_ROW1_3UP" Then
Rows("27:32").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_3UP" Then
Rows("33:38").EntireRow.Hidden = False
End If

If Range("B39").Value = "Choose" Then
Rows("40:51").EntireRow.Hidden = True
ElseIf Range("B39").Value = "0" Then
Rows("40:51").EntireRow.Hidden = True
ElseIf Range("B39").Value = "1" Then
Rows("40:45").EntireRow.Hidden = False
ElseIf Range("B39").Value = "1" Then
Rows("46:51").EntireRow.Hidden = True
ElseIf Range("B39").Value = "2" Then
Rows("40:51").EntireRow.Hidden = False
End If
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Does B26 hold the value "Choose" in Proper case ??
or is it "choose" or "CHOOSE" ??
in which case it won't work...
If that's the problem, put this line BEFORE the start of the Sub
Code:
Option Compare Text
 
Upvote 0
Hi Michael - I added the command you provided and got a message "Compile error: Invalid inside procedure." The data validation drop-down looks like this with "Choose" being exact:

Choose
PROD_ROW1_1UP_LFT
PROD_ROW1_1UP_LFT_RATING
PROD_ROW1_1UP_RT_RATING
PROD_ROW1_2UP
PROD_ROW1_3UP

<colgroup><col></colgroup><tbody>
</tbody>
 
Upvote 0
Note my comment
Rich (BB code):
put this line BEFORE the start of the Sub

Do the other references to B26 work ??
is the Data Validation dropdown on the same sheet ?
AND
I know it's a dumb question......it is definitely B26 ??
 
Upvote 0
The only working reference for B26 is "Choose" because the rows are all hidden no matter the command.
The data validation is on another tab used for all drop-downs within the workbook. I tried to post an image of B26, but it posted a bunch of garbled text. :(
 
Last edited:
Upvote 0
Try putting this at the beginning of the code
Code:
rows("23:51").EntireRow.Hidden = false
This will give you a clean slate to work with for the rest of the code!
 
Upvote 0
That worked!!!
But - this part is not hiding the 2nd set of the rows underneath ("33:38") when "PROD_ROW1_2UP" is chosen:
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("27:28").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("29:32").EntireRow.Hidden = False
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
Rows("33:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_3UP" Then
Rows("27:32").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_3UP" Then
Rows("33:38").EntireRow.Hidden = False
 
Upvote 0
That's because you have multiple conditions meeting the one statement...you'll have to join them, like this
Code:
ElseIf Range("B26").Value = "PROD_ROW1_2UP" Then
   Rows("27:28").EntireRow.Hidden = True
   Rows("29:32").EntireRow.Hidden = False
   Rows("33:38").EntireRow.Hidden = True
ElseIf Range("B26").Value = "PROD_ROW1_3UP" Then
   Rows("27:32").EntireRow.Hidden = True
   Rows("33:38").EntireRow.Hidden = False
 
Upvote 0
thank you!!!! I like that it's packaged up neatly too! Now another one quit working - wawawa
Row 24 won't hide - if I hide it manually, it unhides with N command which is the opposite of what I am trying to accomplish:

If Range("B23").Value = "N" Then
Rows("24").EntireRow.Hidden = True
ElseIf Range("B23").Value = "Y | N" Then
Rows("24").EntireRow.Hidden = True
ElseIf Range("B23").Value = "Y" Then
Rows("24").EntireRow.Hidden = False
End If
 
Upvote 0
maybe this....
Code:
If Range("B23").Value = "N" Or Range("B23").Value = "Y | N" Then
Rows("24").EntireRow.Hidden = True
ElseIf Range("B23").Value = "Y" Then
Rows("24").EntireRow.Hidden = False
End If
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,268
Members
449,149
Latest member
mwdbActuary

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