Why does code cause "lockup"?

  • Thread starter Thread starter JMay
  • Start date Start date
J

JMay

Below code works, but focus is not returned to screen interface; sys seems
"locked-up")
I must Control-Break to continue.

Sub Worksheet_Change(ByVal Target As Range)
Dim LrowInC As Long
LrowInC = Range("C65536").End(xlUp).Row
Range("D3") = "C" & LrowInC
End Sub
 
Sub Worksheet_Change(ByVal Target As Range)
Dim LrowInC As Long
On Error goto ErrHandler
LrowInC = Range("C65536").End(xlUp).Row
Application.EnableEvents = False
Range("D3") = "C" & LrowInC
ErrHandler:
Application.EnableEvents = True
End Sub

if you change a cell in the change event, you trigger the change event again
and again and again . . .
Unless you take some action to prevent it.
 
You are retriggering the same event.

Try:

Sub Worksheet_Change(ByVal Target As Range)
Dim LrowInC As Long
LrowInC = Range("C65536").End(xlUp).Row
Application.EnableEvents = False
Range("D3") = "C" & LrowInC
Application.EnableEvents = True
End Sub
 
Thanks Rob - I now understand!!
JMay

Rob van Gelder said:
You are retriggering the same event.

Try:

Sub Worksheet_Change(ByVal Target As Range)
Dim LrowInC As Long
LrowInC = Range("C65536").End(xlUp).Row
Application.EnableEvents = False
Range("D3") = "C" & LrowInC
Application.EnableEvents = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top