MrMadHatter
New Member
- Joined
- Nov 19, 2016
- Messages
- 5
Hello,
I have the following VBA code that displays a specific row based on a value selected from a drop-down (otherwise it's hidden):
That basically displays row 26 when the user selects 'Yes' in B9 but keeps it hidden if the user selects 'No'. I now need to extend this code to consider another cell and display an additional row.
So, if the user selects 'Yes' in B9 then I need the code to reference cell B6 to see what value the user has selected there and then show one of two additional rows (40 or 41), e.g. if the user has selected '1' in B6 then show row 40/hide row 41, or if the user has selected '2' in B6 then hide row 40/display row 41.
To sum up, here are the possible scenarios:
User selects 'Yes' in B9 and '1' in B6 - Show rows 26 and 40 (hide row 41)
User selects 'Yes' in B9 and '2' in B6 - Show rows 26 and 41 (hide row 40)
User selects 'No' in B9 and either '1' or '2' in B6 - Hide rows 26, 40 and 41
I'm pretty new to VBA so I was hoping somebody could enlighten me as to the general syntax that's required here. I'm assuming I need to incorporate the And function?
I hope this is clear and thanks for any help on this
I have the following VBA code that displays a specific row based on a value selected from a drop-down (otherwise it's hidden):
Code:
If Target.Address = "$B$9" Then
Range("26:26").EntireRow.Hidden = True
If Target = "Yes" Then
Range("26:26").EntireRow.Hidden = False
End If
End If
That basically displays row 26 when the user selects 'Yes' in B9 but keeps it hidden if the user selects 'No'. I now need to extend this code to consider another cell and display an additional row.
So, if the user selects 'Yes' in B9 then I need the code to reference cell B6 to see what value the user has selected there and then show one of two additional rows (40 or 41), e.g. if the user has selected '1' in B6 then show row 40/hide row 41, or if the user has selected '2' in B6 then hide row 40/display row 41.
To sum up, here are the possible scenarios:
User selects 'Yes' in B9 and '1' in B6 - Show rows 26 and 40 (hide row 41)
User selects 'Yes' in B9 and '2' in B6 - Show rows 26 and 41 (hide row 40)
User selects 'No' in B9 and either '1' or '2' in B6 - Hide rows 26, 40 and 41
I'm pretty new to VBA so I was hoping somebody could enlighten me as to the general syntax that's required here. I'm assuming I need to incorporate the And function?
I hope this is clear and thanks for any help on this