Update balance - Multiple markets in same sheet - VBA

Please post any questions regarding the program here.

Moderator: 2020vision

Update balance - Multiple markets in same sheet - VBA

Postby WBI » Thu Oct 03, 2013 12:49 pm

hi all,

Im quite new to using VBA so this may be a simple this to resolve.
what im trying to do is update the balance/exp when needed/conditions are met.
I currently have all football markets open in the first tab/page then log them to the same sheet.
in cell S1 (and every 10th cell ie S11,S21) i have a formula that tells me if a bet has been cancelled within that market(this is needed as i normally have a lot of bets firing off and stake is based on balance...so bets get cancelled due to available balance) - Y/N, (also covers market state etc)
In cell AL1 i have a formula that counts all the 'Y's in S:S to the last market, output = 1,2,3 etc (i found i needed to do this so if there isnt a 'Y' in S1 but in S11 the macro will trigger)
The macro observes cell $AL$1, if>=1 then
look in S1 and every 10th for 'Y' then
if 'Y' it will update balance for that market by putting 'U' in the relevant 'J#' cell.

This all works perfectly, however after a few hours of running the computer becomes unresponsive/frozen. (disable macro=no problem), this has me thinking i need to flush mem/cache/whatever but like i said im new to this so may need something different.

my code:-
Module

Code: Select all
Sub updatebalance()
            Range("S1").Select
                    Do Until IsEmpty(Selection.Value)
            If ActiveCell.Value = "Y" Then
                 ActiveCell.Offset(1, -9).Value = "U"
            End If
    ActiveCell.Offset(10, 0).Select
Loop
End Sub


Sheet1
Code: Select all
Private Sub worksheet_change(ByVal target As Range)
    If target.Columns.Count = 16 Then
        Application.EnableEvents = False
       With Application
        .EnableEvents = False
        .ScreenUpdating = False
        If UCase(Me.Range("$AL$1").Value) >= 1 Then
            Call updatebalance
        End If
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    End If
End Sub


BA version 1.1.0.65z9c

Cheers
WBI
WBI
 
Posts: 8
Joined: Tue Jan 29, 2013 12:21 am

Postby osknows » Thu Oct 03, 2013 4:52 pm

Hello,

You may not need code at all. In the latest beta versions of BA in options/preferences/general there is an option for balance refresh rate. If you set this to something reasonable like 60 then the balance will update every 60 seconds.

I've always been led to believe that refreshing the balance too often is detrimental to the performance of BA so wouldn't recommend refreshing more than once every 60seconds. Things may have changed though?

If you still want to use code then you could use the following

Code: Select all
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Columns.Count <> 16 Then Exit Sub
   
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
        If UCase(Me.Range("$AL$1").Value) >= 1 Then
            Call updatebalance(Target.Parent)
        End If
        .ScreenUpdating = True
        .EnableEvents = True
    End With

End Sub


Code: Select all
Option Explicit

Const balanceRateSec As Long = 60
Dim lastBalanceUpdate As Date

Sub updatebalance(ByVal ws As Worksheet)
Dim timeNow As Date

    'With timer
    timeNow = Now
    With ws
        If .Range("S1").Value = "Y" And _
            DateDiff("s", lastBalanceUpdate, timeNow) > balanceRateSec Then
                lastBalanceUpdate = timeNow
                ws.Range("Q2").Value = "U"
        End If
    End With
   
'    'Without Timer
'    With ws
'        If .Range("S1").Value = "Y" Then
'            ws.Range("Q2").Value = "U"
'        End If
'    End With

End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby WBI » Thu Oct 03, 2013 9:29 pm

cheers Osknows,

it seems the beta version is perfect for my needs as i use the 'F**' function in my triggers, that combined with auto refresh of the balance.
However ill have a look at your code tomorrow and see how it compares.

Regards
WBI
WBI
 
Posts: 8
Joined: Tue Jan 29, 2013 12:21 am


Return to Help

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 24 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.