Hello Process,
Welcome to the Forum!
The Stack is a dedicated area of memory used to store the pointers to results of operations, values of variables and other Sub or Function calls. When data is added to the stack or "pushed" onto the stack, sometime later it will be removed or "popped" from the stack. Most of the time these operations are automatic and transparent to the programmer.
The exception to this rule is when writing code for the Worksheet_Change and Worksheet_SelectionChange events. You can easily create what is known as a Cascade event. This happens when your code triggers the event again. This places the address of the event procedure on the stack. The code calls the event again and the process repeats until there is no stack space left. In all other operating systems I have used, the stack has always been managed to prevent programs from writing into main memory and crashing the system. This is not true with Windows.
I have made a few changes to your code to prevent the cascade failure. The key is to disable and re-enable event handling.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If ActiveCell = "" Then
Sheet1.Range("E2") = Sheet1.Range("e2").Value
Else
Sheet1.Range("E2") = ActiveCell.Value
Sheet1.Range("E1") = ActiveCell.Address
ActiveCell.Offset(1, 0).Select
End If
Application.EnableEvents = True
End Sub
Bookmarks