The behaviour of Worksheet_Calculate event – stored events

Kolobok

New Member
Joined
May 11, 2011
Messages
20
Greetings fellow Excel users! Let me first begin by saying that this is my first post on this forum (actually on any forum), so please forgive me if I inadvertently break any rules for making posts. And I would also like to thank you for taking time out to read my post.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Now, let me describe the problem I’m having (Windows 7 Ultimate, Excel 2010) by giving you a set up. Take a Workbook with 2 Sheets. Sheet 2 Cell A1 has a formula =Sheet1!A1, EnableCalculation property of Sheet2 to TRUE and in Sheet2 Object there is a Sub
<o:p></o:p>
Code:
Private Sub Worksheet_Calculate()
    i = MsgBox("Value " & Me.Range("A1").Value, vbOKOnly)
End Sub

In Module1 there is a SUB<o:p></o:p>

Code:
Public Sub mySub()
    Application.EnableEvents = False
    ThisWorkbook.Worksheets(2).EnableCalculation = True
    ThisWorkbook.Worksheets(2).EnableCalculation = False
    Application.EnableEvents = True
End Sub

Now, enter 1 in Sheet1 Cell A1 – a message box with “Value 1” is displayed. Next, set EnableCalculation property of Sheet2 to FALSE and enter 2 in Sheet1 Cell A1 – nothing happens. Now, run the mySub in Module 1 – Cell A1 on Sheet2 displays 2 and EnableCalculation property of Sheet2 is set to FALSE. So far, so good. Now enter 3 in Sheet1 Cell A1 – a message box with “Value 2” is displayed!

It would seem that during the execution of mySub a Calculation event was fired (even though Application.EnableEvents was set to FALSE) and the value of 2 was stored (where?) and then this event was released when 3 was entered into Cell A1 on Sheet1 (even though EnableCalculation is set to FALSE for Sheet2). Any clue what’s going on here and how to “fix” this strange behaviour?
Many thanks.<o:p></o:p>
<o:p></o:p>
 

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)
The 2 comes from the value in the sheet (since it is not recalculating the formula when you enter 3) but it does appear odd that the calculate event fires again.
 
Upvote 0
Hi, Rory. Thank you for reading and replying to my post. I don't suppose you have tried replicating my set up to see if the problem is specific to my system (Excle 2010, Windows 7 Ultimate)? <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
It's not specific - I can replicate in both XL2010 and XL2003 on WinXP. It seems to be a bug to me (pending further investigation). As and when I get a chance, I'll file it with MS though I doubt it will get a high priority in all honesty as it is not a common scenario.
 
Upvote 0
Yet more strange behaviour of Worksheet_Calculate event: put
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
=Sheet1!A1<o:p></o:p>

in Sheet2, then put <o:p></o:p>

=Sheet2!A1<o:p></o:p>

in Sheet3, and set EnableCalculation property of Sheet2 to FALSE. Now, changing values in cell A1 on Sheet1 will trigger a Worksheet_Calculate event on Sheet3, even though values on both Sheet2 and Sheet1 do not change! Another bug?..<o:p></o:p>
<o:p> </o:p>
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,445
Members
452,915
Latest member
hannnahheileen

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