Multiple "Worksheet_Change Event" in one excel file

Likith

New Member
Joined
Dec 26, 2018
Messages
9
Team ,

I have below VBA code to hide few rows in excel but 2nd code in this is not working in combination with first one . When I do it separately its working fine . Any Suggestions ?


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B7")) Is Nothing Then Exit Sub
If Target = "Y" Then
Rows("17:22").Hidden = True
Rows("11:15").Hidden = False
ElseIf Target = "N" Then
Rows("11:15").Hidden = True
Rows("17:22").Hidden = False
End If


If Intersect(Target, Range("B39")) Is Nothing Then Exit Sub
If Target = "Y" Then
Rows("40:40").Hidden = True
Rows("41:41").Hidden = False
ElseIf Target = "N" Then
Rows("41:41").Hidden = True
Rows("40:40").Hidden = False
End If

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hello Likith,

Try it as follows:-
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If [COLOR=#ff0000]Not[/COLOR] Intersect(Target, Range("B7")) Is Nothing Then
If Target = "Y" Then
            Rows("17:22").Hidden = True
            Rows("11:15").Hidden = False
ElseIf Target = "N" Then
            Rows("11:15").Hidden = True
            Rows("17:22").Hidden = False
      End If
[COLOR=#ff0000]End If[/COLOR]


If [COLOR=#ff0000]Not[/COLOR] Intersect(Target, Range("B39")) Is Nothing Then
If Target = "Y" Then
            Rows("40").Hidden = True
            Rows("41").Hidden = False
ElseIf Target = "N" Then
            Rows("41").Hidden = True
            Rows("40").Hidden = False
      End If
[COLOR=#ff0000]End If[/COLOR]

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
You're welcome Likith.
I'm glad that I was able to help and thanks for the feed-back.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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