If statement locks up excel

velocity1234

New Member
Joined
May 5, 2014
Messages
25
I have the following code. It copies values from one cell to another given a simple criteria when there is a "Change" on the sheet.

The code works, but then it hangs up as if I am overloading the program. Is there an easier way
to code this so it does not hang.

Private Sub Worksheet_Change(ByVal Target As Range)


If Range("LastSPY").Value <= Range("LowestLowSPY").Value Then
Range("LowestLowSPY").Value = Range("LastSPY").Value
End If


If Range("LastSPY").Value >= Range("HighestHighSPY").Value Then
Range("HighestHighSPY").Value = Range("LastSPY").Value
End If


If Range("LastVXX").Value <= Range("LowestLowVXX").Value Then
Range("LowestLowVXX").Value = Range("LastVXX").Value
End If


If Range("LastVXX").Value >= Range("HighestHighVXX").Value Then
Range("HighestHighVXX").Value = Range("LastVXX").Value
End If


End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
It looks like you might be getting cascading events. The Change code changes the value of a cell which calls the Change event, which changes the value of a cell, which calls the Change event, which ....

You can disable the calling of events with
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

'...

Application.EnableEvents = True
End Sub
Be sure to code your routine so that all possibilities include the EnableEvents = True line before exiting the Sub (no Exit Sub).
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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