I am experiencing some very strange behaviour with EnableEvents and am coming to the conclusion that I may have discovered an Excel bug. However, I know that Events can lead to quite subtle behaviour and would appreciate some thoughts.
I have attached a spreadsheet that doesn't do anything very useful, but is designed to exhibit the strange behaviour. With events enabled, if you enter values in the grey-shaded "Scratch Zone" a Worksheet_Change Sub for Sheet1 will update the Results cell with the number of non-zero cells in the Scratch Zone. As expected, if you this behaviour ceases if you click on the "Events Off" button, which simply calls
[vba]Sub restoreEvents()
getResult
Application.EnableEvents = True
End Sub[/vba]
Clicking "Reset" reactives events and updates the Results count.
So far, so good. But now try a copy and paste of, say, B9:C10 to D15. Events are silently disabled, preventing the call of the Worksheet_Change Sub. Clicking "Reset" will fix things, until such time as you copy & paste again. Surely copy & paste can't break events, because so many people use Events to capture changes arising from copy & paste? Aha, here's where it really gets strange. Cells contain B5 to F5 have a silly little VBA function called "getlast" which returns the row number (as labelled in column A) of the last non-zero/non-empty cell. It's the existence of a VBA function call in the sheet that seems to cause the problem. If you clear the contents of B5:F5, click reset and try copy & paste, then events will no longer be broken? The problem doesn't seem to depend on the particular VBA function used.
This seems to suggest that using VBA functions and Events is a dangerous mix. Any theories?
Sean.