- Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count = 16 Then
'[if bet conditions are met]
Application.EnableEvents = False
[Q5] = "BACK" 'trigger
[R5] = 1000 'odds
[S5] = 2 'stake
Sleep 1000 'pause for 1 second *
DoEvents 'yield to allow BA to interact with Excel
'[do other stuff]
Application.EnableEvents = True
End If
End Sub
With a refresh rate in BA of 1 second, will DoEvents as used in the above example allow BA to reliably read the trigger and submit the bet BEFORE the next line of code is executed?
Or should DoEvents be called repeatedly in a loop instead in this case (e.g. Do While bet ref is empty)? I gather that such loops are CPU-heavy and so could potentially be an issue when logging multiple markets, which is the point of all this.
Thanks
------------------
* To use the Sleep function the following statement must be inserted at the top of the module (or if declared as Public instead, any module can use the function):
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
#End If
Other pausing methods are commonly used but it appears that they have certain drawbacks:
https://stackoverflow.com/questions/1544526/how-to-pause-for-specific-amount-of-time-excel-vba