VBA code help please

Please post any questions regarding the program here.

Moderator: 2020vision

VBA code help please

Postby danjuma » Tue Mar 02, 2010 5:50 pm

Say if cell F5 = 10.0, and I want cell AA1 to have a particular value (let's say 1 for this example) only if F5 has been equal to 10.0 for a period of say at least 5 seconds (basically trying to avoid odd spikes in the market), I presume I would need a VBA code for this. Could somebody assist with a code for this please?

Many thanks
Dan
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby Ian » Tue Mar 02, 2010 6:25 pm

Could you simply count the number of refreshes that F5 has remained constant ?
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby danjuma » Tue Mar 02, 2010 6:30 pm

How would you do this Ian? Thanks
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby Ian » Tue Mar 02, 2010 7:20 pm

Something like this .........



Code: Select all
Dim prevOdds As Long
Dim refreshCount As Integer

Private Sub Worksheet_Change(ByVal Target As Range)

    With Sheets("Current Race")
   
       If Target.Columns.Count = 16 Then
   
               
                If .Cells(5, 6).Value = prevOdds Then
               
                    refreshCount = refreshCount + 1
                   
                Else
                                   
                    refreshCount = 0
               
                End If
               
                prevOdds = .Cells(5, 6).Value
               
                If refreshCount >= 5 Then
               
                    .Cells(1, 27).Value = "Y"
                   
                Else
               
                    .Cells(1, 27).Value = ""
                                   
                End If
     
       End If

    End With

End Sub
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby danjuma » Tue Mar 02, 2010 7:47 pm

Ian wrote:Something like this .........



Code: Select all
Dim prevOdds As Long
Dim refreshCount As Integer

Private Sub Worksheet_Change(ByVal Target As Range)

    With Sheets("Current Race")
   
       If Target.Columns.Count = 16 Then
   
               
                If .Cells(5, 6).Value = prevOdds Then
               
                    refreshCount = refreshCount + 1
                   
                Else
                                   
                    refreshCount = 0
               
                End If
               
                prevOdds = .Cells(5, 6).Value
               
                If refreshCount >= 5 Then
               
                    .Cells(1, 27).Value = "Y"
                   
                Else
               
                    .Cells(1, 27).Value = ""
                                   
                End If
     
       End If

    End With

End Sub


Sir, you are a gent, many thanks!!! :D

Just one question, with the statement: With Sheets("Current Race"), is "Current Race" referring to the name of the sheet or something and do I need to change it to the name of my sheet. Sorry, if it's a stupid question, am not well versed in VBA. Cheers.
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby Ian » Tue Mar 02, 2010 8:09 pm

Yes "Current Race" is the name of the sheet so you would need to change it to whatever sheet you are logging to.
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby danjuma » Tue Mar 02, 2010 8:12 pm

Ian,

Just one more thing that came to mind. It looks like you code is based on the assumption that BA is refreshing every second, what if it was refreshing every 0.3 seconds? Should I just change the statement: If refreshCount >= 5 Then to something like If refreshCount >= 15 Then ?

Cheers
Dan
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby danjuma » Tue Mar 02, 2010 8:13 pm

Ian wrote:Yes "Current Race" is the name of the sheet so you would need to change it to whatever sheet you are logging to.


Thanks.
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm

Postby Ian » Tue Mar 02, 2010 8:25 pm

danjuma wrote:Ian,

Just one more thing that came to mind. It looks like you code is based on the assumption that BA is refreshing every second, what if it was refreshing every 0.3 seconds? Should I just change the statement: If refreshCount >= 5 Then to something like If refreshCount >= 15 Then ?

Cheers
Dan


Exactly.
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby danjuma » Tue Mar 02, 2010 8:37 pm

Ian wrote:
danjuma wrote:Ian,

Just one more thing that came to mind. It looks like you code is based on the assumption that BA is refreshing every second, what if it was refreshing every 0.3 seconds? Should I just change the statement: If refreshCount >= 5 Then to something like If refreshCount >= 15 Then ?

Cheers
Dan


Exactly.


Many thanks.
User avatar
danjuma
 
Posts: 347
Joined: Mon Apr 21, 2008 4:17 pm


Return to Help

Who is online

Users browsing this forum: No registered users and 40 guests

Sports betting software from Gruss Software


The strength of Gruss Software is that it’s been designed by one of you, a frustrated sports punter, and then developed by listening to dozens of like-minded enthusiasts.

Gruss is owned and run by brothers Gary and Mark Russell. Gary discovered Betfair in 2004 and soon realised that using bespoke software to place bets was much more efficient than merely placing them through the website.

Gary built his own software and then enhanced its features after trialling it through other Betfair users and reacting to their improvement ideas, something that still happens today.

He started making a small monthly charge so he could work on it full-time and then recruited Mark to help develop the products and Gruss Software was born.

We think it’s the best of its kind and so do a lot of our customers. But you can never stand still in this game and we’ll continue to improve the software if any more great ideas emerge.