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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

KenMillard

Board Regular
Joined
Apr 25, 2007
Messages
151
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.
 

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
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,
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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
 

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
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.
 

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
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.
 

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
Ok give me a little while and I'll rewrite it and then post it for you :)
 

yoko

Active Member
Joined
Sep 5, 2006
Messages
349
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
 

Forum statistics

Threads
1,181,362
Messages
5,929,534
Members
436,676
Latest member
Mavri

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
Top