I'm trying to automate my back bets for the horses if the price stays below a certain percentage of BSP for n seconds.
I have setup my spreadsheet using the "Reload quick pick list at midnight" sheet as my starting point. Columns AB:AW have criteria in them that the Trigger column Q references. This works fine and has been losing me money just fine!!

Due to downward spikes the back bet threshold is being reached for a split second and firing the BACK command. I've tried putting in criteria if it's close to the lay price but this still hasn't worked.
So now I want to place the BACK if the threshold is reached and held for a certain time period, say 3 seconds for example. I have changed my spreadsheet to have range AA5:AA44 as the range that has the IF commands in to say whether to BACK that row.
I would like column Z to have a timestamp (just time) to be entered by VBA if the corresponding AA cell has BACK in it. My Trigger (Q column) cell will then have a formula comparing the Z cell and $C$2 for the time now.
This is my VBA at the moment, but it is not entering the time in the Z column. I've tried loops, Ifs, Intersects and none seem to work! I have no experience of VBA so I've been trying to customise code I see on the internet for adding timestamps, but i think my problem is that these are static spreadsheets that aren't refreshing.
As a second query, I then want column Z to be cleared when the market changes to the next race.
- Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False
Dim xCellColumn As Integer
Dim xTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xCellColumn = 26
xTimeColumn = 25
xRow = Target.row
xCol = Target.Column
If Target.Text = "BACK" Then
If xCol = xCellColumn Then
Cells(xRow, xTimeColumn) = Time()
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xCellColumn Then
Cells(xRg.row, xTimeColumn) = Time()
End If
Next
End If
End If
If triggerQuickPickListReload Then
triggerQuickPickListReload = False
Range("Q2").Value = -3
triggerFirstMarketSelect = True
Else
If triggerFirstMarketSelect Then
triggerFirstMarketSelect = False
Range("Q2").Value = -5
End If
End If
Application.EnableEvents = True
End Sub