Crazy loop in shared workbook when deleting rows...

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Hi,

I got a spreadsheet which is doing a really strange thing.

The sheet is full of macros and some under the Worksheet_Change event but I have if statements to only run the code if certain cells are changed.

Now when the workbook is unshared and I delete rows 1000 to 65536 everything happens as fine, the rows are deleted.

When the workbook is shared and I do the same thing excel goes in to some never ending loop where the sheet looks like its deleting those rows over and over (I think, I don’t really know what its doing)

I can delete 1 row fine and I can delete several rows fine its just when I from 1000 to the end row.

Any ideas what could be causing this?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
It would seem that the code attached to the worksheet change event is making a change that re-triggers the same event.

I would start by reviewing the code attached to the change event to see if there is something there you missed. Then I would try putting a break point at the start of the change event and step through to make sure the conditional statements are executing as you intended. You may also want to add somthing like
Code:
debug.print target.address
to the beggining of the change event so you can monitor what cell is triggering the change event.

If nothing shows up there try looking at other events that may either be re-triggering themselves or going back and forth with the change event.
 
Upvote 0
Hi,

Thanks for the reply. In the end I just removed the code what was deleting the cells. I turned off EnableEvents before the delete code runs so I'd have thought that would stop the event being triggered again.

Cheers,
 
Upvote 0
I turned off EnableEvents before the delete code runs so I'd have thought that would stop the event being triggered again.
Hi,

Indeed, that should work, but perhaps your code is somehow more complex and turning on EnableEvents again unexpectedly. You could investigate the problem, by setting a breakpoint at the start of your code and then moving on with function key F8 step-by-step.

kind regards,
Erik
 
Upvote 0
The odd thing was it only did this loop when the sheet was shared. If it was not shared it would delete the rows with out problem. I wondered if it was just a bug within excel.
 
Upvote 0
oh, yes!? ONLY when it is shared!?
I cannot test your problem, so I called some guys to take a look here. Hopefully they will jump in.
In the mean time, it would be good to post (part of) the code you were using.
 
Upvote 0
This is the code which causes the infinate loop when the sheet is shared. Works fine when the spreadsheet is not shared.

:)

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim l As Integer

On Error Resume Next
    
    With Application
        .ScreenUpdating = False
        .Calculation = xlCalculationManual
        .EnableEvents = False
    End With
    
    With ThisWorkbook
    
        For l = 4 To .Worksheets.Count
            .Worksheets(l).Range("1001:65536").Delete
        Next l
    
    End With
    
    With Application
        .ScreenUpdating = True
        .Calculation = xlCalculationAutomatic
        .EnableEvents = True
    End With
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,027
Members
448,543
Latest member
MartinLarkin

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