firlandsfarm wrote: ↑Mon Nov 18, 2019 1:43 pm
I understand your comments … I switched away from ...Worksheet_Change … following Shaun's earlier post when he advised the wb will check the Target every time there is a change to any cell in the ws and so slow it down but maybe with Callum's suggestions that can be speeded up enough to make ...Worksheet_Change … viable again.
Yep, everyone has their own way of coding things and Shaun does seem to like timers rather than Worksheet_Change, personally I'd much rather be reacting to when the odds change than hoping I'll drop in at the right time with some timer. But so much depends on what your betting approach entails and if changes in odds or set times are more important. Excel is quite efficient and I simply ensure I exit the Worksheet change routine early if there's no need to run through all the code.
firlandsfarm wrote: ↑Mon Nov 18, 2019 1:43 pm
I also wondered about 'calling' the Sub and actually searched for that with Google but couldn't find anything other than a couple of articles that advised the Sub would be run every time the wb updated so I thought, fair enough … keep looking (for something else!). Is it the use of 'Private Sub' that makes it run at every update?
It's the Worksheet_Change that simply runs the code every time something on the worksheet changes, You get Private and Public Sub's which won't affect what you're doing now and may just confuse things to delve into them now.
Calling the sub routine using Call was just the way I learnt to call sub routines but you can simply enter the name of the routine and omit
Call, I still do it as it makes any code easy for me to spot. Using sub routines usually makes large amounts of coding easier to tweak. What you normally do to stop code continually running is to set a flag to say the code has run and then reset it later. So the 'flag' could be held in memory or simply written to a cell on the sheet as an indication your code has run. So for instance when you run your code Range("B9:K68").ClearContents
you may wish to enter "Y" in Cell AA1 and your code would become
Code: Select all
If Range("F4").Value < 0 And Range("AA1").Value <>"Y" Then Range("B9:K68", "O9:AE68").ClearContents: Range("AA1").Value ="Y"
That way our code will still run but only fire Clearcontents once rather than each refresh. Obviously we'd need to reset cell AA1 to ensure we'd fire next market but that depends what criteria you'd want to reset it ready for the next market. Something like this may be all that's needed to simply reset it when F4 is greater than 0
Code: Select all
If Range("F4").Value > 0 And Range("AA1").Value <>"N" Then Range("AA1").Value ="N"
firlandsfarm wrote: ↑Mon Nov 18, 2019 1:43 pm
As for sample code sets in the Forum, yep, there's plenty … all different and all amended by long debate. But I couldn't find one that would scroll through pairs of events.
Not sure what you mean by pairs of events.