worksheet_change not working

Nichole09

Board Regular
Joined
Aug 27, 2016
Messages
132
Can anyone tell me why this code wont work? Its working once with only I26, and I have entered Application.EnableEvents = True in the immediate window, and keep saving and closing and reopening to see if that will help make it work. I am not sure why its working only with I26?
Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False

Dim R As String
R = "Received"

If Intersect(Target, Range("e37")) Is Nothing Then
Exit Sub
Else
Range("i26").Value = R
End If


If Intersect(Target, Range("h37")) Is Nothing Then
Exit Sub
Else
Range("i24").Value = R
End If


If Not Intersect(Target, Range("L37")) Is Nothing Then
Exit Sub
Else
Range("i28").Value = R
End If

Application.EnableEvents = True

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Here you tell VBA to exit the sub if Target is not E37 so the subsequent code is never reached.
Code:
If Intersect(Target, Range("e37")) Is Nothing Then
    Exit Sub ' if Target is not E37 exit the sub
Else
    Range("i26").Value = R
End If
 
Upvote 0
Thank you Norie. I think, I might understand. Hopefully..... should this be correct?

Code:
Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim R As String
R = "Received"
If Not Intersect(Target, Range("e37")) Is Nothing Then
Exit Sub
Else
Range("i26").Value = R
End If
 

If Not Intersect(Target, Range("h37")) Is Nothing Then
Exit Sub
Else
Range("i24").Value = R
End If
 
 
If Not Intersect(Target, Range("L37")) Is Nothing Then
Exit Sub
Else
Range("i28").Value = R
End If
Application.EnableEvents = True
End Sub

[code]
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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