Break out of a loop in Excel2007?

D

Don

I created some code that gets Excel in a loop when I open the file and I need
to know how to break out? It is in the Sheet option using the
Application.EnableEvents in Office 2007 and will not let me break out of the
loop and I have to close doing a cntl+alt+delete and hard crashing Excel.

I have updated I think all the files, but if I have some not updated and
people move to Office 2007, I would like another way to get out?

Any help?

see code below from the sheet

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Range(Cells(6, 6), Cells(7, 7)).Select
Selection.ClearContents
Application.EnableEvents = False
End Sub
 
B

Bob Umlas

Change to:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range("F6:G7")ClearContents
Application.EnableEvents = True
End Sub
 
P

Per Jessen

Hi

You have to set EnableEvents = False before anything else, and set
=true again later:

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Range(Cells(6, 6), Cells(7, 7)).ClearContents
Application.EnableEvents = True
End Sub

Best regards,
Per
 
J

Jacob Skaria

Hi Don

You can use 'Ctrl'+'Pause/Break' buton to break a running code...
You can even give it a try......

If this post helps click Yes
 
D

Don

sorry, the loop is because enable events is turned on and if there is an
update on the page, it will start from the top again. Should be turning it
to off first so it will go through once but it gets stuck in 2007 and will
not let you break out
 
D

Don

sorry, tried that an no luck.

Jacob Skaria said:
Hi Don

You can use 'Ctrl'+'Pause/Break' buton to break a running code...
You can even give it a try......

If this post helps click Yes
 

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

Top