VBA Two Ranges of Row Code

tlc53

Active Member
Joined
Jul 26, 2018
Messages
399
Hi there,

I am trying to write a code which hides/unhides rows depending on whether Yes or No is selected. The first part of my code works fine however, I am having trouble with the second part. How do I unhide two ranges of rows? I would prefer not to write two lines of code because it causes a stutter affect.

If Range("Plus_YN_2") = "NO" Then
Rows("82:101").EntireRow.Hidden = True
End If


If Range("Plus_YN_2") = "YES" Then
Rows("82:90,100:101").EntireRow.Hidden = False
End If

Thanks very much!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
maybe combine the two in an if else

Code:
[COLOR=#333333]If Range("Plus_YN_2") = "NO" Then[/COLOR]
[COLOR=#333333]Rows("82:101").EntireRow.Hidden = True
[/COLOR]Else
[COLOR=#333333]Rows("82:90,100:101").EntireRow.Hidden = False[/COLOR]
[COLOR=#333333]End If
[/COLOR]
 
Upvote 0
Thanks Nine Zero. However, it won't run. I think it doesn't like the "End If".

Here's the code I put in..

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("Plus_YN_2") = "NO" Then
Rows("82:101").EntireRow.Hidden = True
Else
Rows("82:90,100:101").EntireRow.Hidden = False


End If
 
Upvote 0
Try changing Rows to Range.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Range("Plus_YN_2") = "NO" Then
        Range("82:101").EntireRow.Hidden = True
    Else
        Range("82:90,100:101").EntireRow.Hidden = False
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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