Excel update on new market only partial

Please post any questions regarding the program here.

Moderator: 2020vision

Excel update on new market only partial

Postby greenfingers » Fri Feb 17, 2012 1:07 pm

Hi, apologies if this has always been the case but I'm having trouble with a few of my spreadsheets (that record odds movements) relating to when a new market loads.

The problem occurs when going to a new horse race market which has fewer runners than the previous race.

The problem is that the first update that happens seems to only cut data for the "excess" number of runners from the previous race's data before actually updating with all the data for the new race. Confused :? I know, I just can't explain it!

Here's an example. I'm recording the data for a 20 runner race. The next race happens to be a 12 runner race. When the race is selected, the first update cuts all the data for the bottom 8 runners in the previous race. The race name, names of the first 12 runners etc all stay the same and are not changed yet. On the next refresh, all the new race data is imported.

This means that the last data captured for the first race only has 12 runners. :twisted:

Problem is, I'm finding this difficult to work around and detect the market change as the market name is still the same when the "excess" runners get wiped.

Phew, sorry that's all a bit longwinded.....

I'm running 1.1.0.66x82.
User avatar
greenfingers
 
Posts: 214
Joined: Mon Mar 23, 2009 3:10 pm

Postby osknows » Fri Feb 17, 2012 1:17 pm

You could detect the change of market name in cell A1 and clear a range one-time only. Eg this in a sheet object will clear range A5:Z55 once when the market changes


Code: Select all
Option Explicit

Dim currentMarket As String

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count = 16 Then
    Application.EnableEvents = False

    With Target.Parent

        If .Range("A1").Value <> currentMarket Then
            currentMarket = .Range("A1").Value
            .Range("A5:Z55").ClearContents
        End If
    End With

   Application.EnableEvents = True
End If

End Sub
Last edited by osknows on Fri Feb 17, 2012 1:32 pm, edited 1 time in total.
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby alrodopial » Fri Feb 17, 2012 1:18 pm

After the
Application.EnableEvents = False
add the

If Target.Cells(1, 1).Value = "" Then Exit Sub

Before entering the new data BA checks if the number of runners in the sheet are more that those that are about to be copied.
If they are , it deletes the existing data at the sheet and then rights the new data, so there may be a "false" 16 columns uptade.
At this update the cell(1,1) has no data so -> exit sub
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm

Postby greenfingers » Fri Feb 17, 2012 5:49 pm

Thanks very much for your quick replies guys. I'll try them out in the morning.

osknows - I don't really understand how 'target' works and I haven't seen target.parent before, what's that about?

Cheers.
User avatar
greenfingers
 
Posts: 214
Joined: Mon Mar 23, 2009 3:10 pm

Postby osknows » Fri Feb 17, 2012 7:47 pm

When the worksheet change event triggers the Target variable is the range of cells which have changed.

That range of cells will be on a worksheet, it's 'parent'; the worksheet also has a 'parent' the workbook etc

Using 'With Target.Parent' references the sheet but doesn't require a worksheet name or codename to be hardcoded.

Try this in a sheet object

Code: Select all
Private Sub Worksheet_Change(ByVal Target As Range)

MsgBox Target.Address
MsgBox Target.Parent.Name
MsgBox Target.Parent.Parent.Name
End Sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby greenfingers » Sat Feb 18, 2012 12:32 pm

Thanks again guys. alrodopial, I didn't see at first why your line of code works, but I get it now! I see what you mean about testing for the 'false' update. Thanks for the explanation osknows. The penny has dropped!
:)
User avatar
greenfingers
 
Posts: 214
Joined: Mon Mar 23, 2009 3:10 pm

Postby alrodopial » Sat Feb 18, 2012 1:47 pm

Small correction, it should be insert between these two lines:
Code: Select all
If Target.Columns.Count = 16 Then
    Application.EnableEvents = False
alrodopial
 
Posts: 1384
Joined: Wed Dec 06, 2006 9:59 pm


Return to Help

Who is online

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