by Gavin » Fri Jul 31, 2015 4:51 pm
Hi Shaun,
Keep in mind that if you set Application.EnableEvents to False, Cymatic won't be able to respond to any triggers whilst events are turned off, because Cymatic relies upon 'events' occurring in Excel in the sheets to which it is connected. When events occur in Excel, Cymatic checks for trigger commands and Status cells being empty, in order to find valid command and act upon them.
When your code sets EnableEvents back to true, Cymatic won't instantly detect that you cleared some Status cells. This is because you cleared them whilst the event firing mechanism was turned off.
In which case Cymatic will only detect that there are valid commands with empty Status cells, NEXT time an 'event' is fired in Excel. So if for example, you have formulae in the sheet that relate to the market data cells, then the recalculation of those formulae will trigger fire the Cymatic to detect the triggers when the data is next refreshed, which will obviously delay it responding to your code that cleared the Status cells, until the next refresh occurs, i.e. it is delayed by a duration equal to one refresh cycle (the setting for price refresh intervals in the Cymatic settings).
Even worse would be if the user does not have an formulae in the Cymatic worksheet. In which case Cymatic would only see an event being fired the next time the user changes a trigger cell manually or VBA code changes it (with EnableEvents not set to false).
Strictly speaking you could just comment out the lines that turn the EnableEvents on / off, because you have wisely put it a test at the top of the code block to check whether the changed cells are likely to be the ones that your code just changed (using the intersect command). Obviously without setting EnableEvents to false, your code will fire twice, because it changes cell and thus causes the Worksheet_Change event to fire again. This is fine though because your INTERSECT command prevents an infinite loop.
It could be argued that it is better to put any such VBA code into the Worksheet_Calculate event of a separate sheet (lets call the sheet 'Rules' for example). Then put a simple formula somewhere in Rules that refers to the last refreshed time (cell C4) in the Cymatic sheet. The formula would be:
=Cymatic!C4
This formula would therefore be recalculated every time new data arrive in the Cymatic sheet. This causes Rules' Worksheet_Calculate event to fire. So you can happily put code in Rules' Worksheet_Calculate event, to clear the Status cells in Cymatic, without causing re-entrancy into the Worksheet_Calculate event in Rules.
Kind regards,
Gavin
Kind regards,
Gavin