want to apply multiple Private Sub Worksheet_Change(ByVal Target As Range)?

aashish83

Board Regular
Joined
Feb 15, 2022
Messages
62
Office Version
  1. 365
Platform
  1. Windows
I need to run the below multiple times (24 times) to be precise in a single sheet- Basically there is answer box in C column (starting from C19) after every 4 rows and i want to hide the in between rows if the answer column C particular Cell is "Yes"

Sub MacroCF1()
Range("A20:A23").EntireRow.Hidden = False
End Sub
Sub MacroCF2()
Range("A20:A23").EntireRow.Hidden = True
End Sub

Private Sub Worksheet_Changes(ByVal Target As Range)

If Not Intersect(Target, Range("C19")) Is Nothing Then
Select Case Target.Value
Case "Yes"
Call MacroCF2
Case "No"
Call MacroCF1

End Select
End If
End Sub
 
You can only have one of each available event in each worksheet & you must not rename them as shown below.

Rich (BB code):
Private Sub Worksheet_Changes(ByVal Target As Range)

try this update to your code & see if does what you want

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Me.Range("C19,C24,C29,C34,C39,C44,C49,C54,C59,C64,C69,C74,C79," & _
                                   "C84,C89,C94,C99,C104,C109,C114,C119,C124,C129,C134")) Is Nothing Then

        Target.Offset(1).Resize(4).EntireRow.Hidden = UCase(Target.Value) = "YES"
    End If
End Sub

Code assumes values in Column C are changed either directly or by code (not formula)

Hope I have a the cell addresses correct but update if required

Dave
 
Upvote 0
Solution
You can only have one of each available event in each worksheet & you must not rename them as shown below.

Rich (BB code):
Private Sub Worksheet_Changes(ByVal Target As Range)

try this update to your code & see if does what you want

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Me.Range("C19,C24,C29,C34,C39,C44,C49,C54,C59,C64,C69,C74,C79," & _
                                   "C84,C89,C94,C99,C104,C109,C114,C119,C124,C129,C134")) Is Nothing Then

        Target.Offset(1).Resize(4).EntireRow.Hidden = UCase(Target.Value) = "YES"
    End If
End Sub

Code assumes values in Column C are changed either directly or by code (not formula)

Hope I have a the cell addresses correct but update if required

Dave
Worked like a Charm!!!! Thanks Dave
 
Upvote 0
Most welcome & appreciate your feedback

Dave
Hi Dave Can i request your help on another query that i have

What i want is what below the below code does but in a new WorkBook and if i have multiple ranges? for e.g. my second range would be B19:B2700 and if that is so it should Copy Sheet FSR Level B instead of FSR Level A and third Range would be C19:C2700 and output to be FSR Level C sheet. Greatly appreciate any help on this

Sub Create_CentralA()
Dim sh1 As Worksheet, sh2 As Worksheet


Set sh1 = Sheets("FSR Level A")


Set sh2 = Sheets("BI")



For Each c In sh2.Range("A35:A2700", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants)
sh1.Copy After:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
Next

End Sub
 
Upvote 0
Its a different question & should be in a new thread where others here can offer assistance.

Dave
 
Upvote 0

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