Combine multiple "Private Sub Worksheet_Change(ByVal Target As Range)"

sanky9192

New Member
Joined
Sep 13, 2016
Messages
3
Hi,

I need to combine following codes which will change the attributes of the cell as well as worksheet.
And I need it in single worksheet.

Formula 1

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("I6").Value = "NO" Then
Rows("52:55").EntireRow.Hidden = True
ElseIf Range("I6").Value = "YES" Then
Rows("52:55").EntireRow.Hidden = False
End If
Exit Sub

Formula 2

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("I6").Value = "Yes" Then
Worksheets("Sheet2").Visible = True
Else
Worksheets("Sheet2").Visible = False
End If
End Sub



Thanks in advance.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hope this helps.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Range("I6").Value
    Case "NO"
        Rows("52:55").EntireRow.Hidden = True
        Worksheets("Sheet2").Visible = False
    Case "YES"
         Rows("52:55").EntireRow.Hidden = False
        Worksheets("Sheet2").Visible = True
    Case Else
        Worksheets("Sheet2").Visible = False
End Select
End Sub
 
Upvote 0
Yeah , it worked.

But I've used other method,

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("H6").Value = "NO" Then
Rows("52:57").EntireRow.Hidden = True
Worksheets("Without GGH").Visible = True
Worksheets("GGH").Visible = False

ElseIf Range("H6").Value = "YES" Then
Rows("52:57").EntireRow.Hidden = False
Worksheets("Without GGH").Visible = False
Worksheets("GGH").Visible = True

End If


End Sub
 
Upvote 0

Forum statistics

Threads
1,214,792
Messages
6,121,612
Members
449,039
Latest member
Mbone Mathonsi

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