VBA help needed- to copy last requested odds to another cell

Please post any questions regarding the program here.

Moderator: 2020vision

VBA help needed- to copy last requested odds to another cell

Postby ladders » Sat Jan 20, 2007 11:17 am

Hi all

Firstly thanks very much to Gary for the program, and the rest of you for the help you have already given in your forum posts.

I'd like to be able to record the odds of the last order i placed on a given selection, let's say on row 5 when using an origin of A1. So, the value I want copied is in R5 (odds) at the instant the order is placed.

I'd like the value copied to Z5. This number forms part of my if formulae in Q5 (trigger) / R5 (odds).

My idea was to create a macro that would copy the value in R5 and paste as a value to Z5 when T5 = PENDING. This macro works fine when I'm not linked to BA and manually enter PENDING, but is unreliable / doesn't often work when linked to BA. I guess that this method of recording the odds is weak because PENDING may not always appear for long enough to activate the macro?

Can anyone help with a better solution for this? or is this the best type of solution and i need to play with timing settings etc? I'm fairly confident with formulae but know very little VBA. I'd like the solution to use as little VBA as possible.

thanks
Paul
ladders
 
Posts: 11
Joined: Wed Jan 17, 2007 1:43 am

Postby Mitch » Sun Jan 21, 2007 10:46 pm

It sounds like your vba is ok, but what method are you using to trigger the code to run? Is it on a timer or a worksheet event?

If you're unsure what I mean you could just post the routine in here if it helps.
User avatar
Mitch
 
Posts: 365
Joined: Sat Nov 19, 2005 12:28 am
Location: Leicester

Postby ladders » Sun Jan 21, 2007 11:40 pm

Hi Mitch

Glad to hear from you - from what i've seen elsewhere on the forum i'm sure you can help!

I have very little VBA knowledge and pieced this together based on a few bits I found on the web for other purposes. As far as I understand, the top bit of code will start up the "PasteOddsReq" macro whenever I open the workbook. Does this then just continually run over and over periodically? or will it run when any cell is changed? Is using the appearance of PENDING the best trigger to record this data?

In addition to the code below, everything between (and including) If and End If is repeated for rows 5-10 (to perform the same task for the top six runners / outcomes.

thanks.

Sub Auto_Open()
Application.OnEntry = "PasteOddsReq"
End Sub


Sub PasteOddsReq()

If Range("T5").Value = "PENDING" Then

Range("R5").Select
Selection.Copy
Range("Z5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

End If
ladders
 
Posts: 11
Joined: Wed Jan 17, 2007 1:43 am

Postby Mitch » Thu Jan 25, 2007 12:18 am

Hi, sorry it took a while to reply but I've not been around much the last few days.

Hopefully we're both going to learn something here, because I've not come across Application.OnEntry before (I only ever learn enough to do what I need to do) so I've just had a play about with it.

It only seems to work when you manually enter something in the sheet, but not when BA pastes its' data there.

I use the Worksheet_Change event handler to run my macro each time BA sends info.

You obviously know something about how to do this, but if I say something that doesn't make sense please shout.

You could get rid of the Auto_Open routine, put your PasteOddsReq routine in a module, then put the following code in the code window for the sheet you have the info put into from BA.

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

    If Target.Columns.Count <> 16 Then Exit Sub
    Application.EnableEvents = False
    PasteOddsReq
    Application.EnableEvents = True
   
End Sub


That will do the job for you. It can be made a little simpler though, so much so that it's hardly worth having a seperate routine for the PasteOddsReq.

This is how I would do it....

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

    If Target.Columns.Count <> 16 Then Exit Sub
    Application.EnableEvents = False
   
    For i = 5 To 10
        If Cells(i, 20) = "PENDING" Then Cells(i, 26) = Cells(i, 18)
    Next i
   
    Application.EnableEvents = True
   
End Sub


The part I've substituted for the call to the original routine looks at lines 5 to 10 in a loop, and if the 20th cell across (col T) has pending in it, puts the value in the 18th cell across (R), into the 26th (Z).

The whole thing goes in the code window for the worksheet you're using.

Like I said above, if anything doesn't make sense please ask.
User avatar
Mitch
 
Posts: 365
Joined: Sat Nov 19, 2005 12:28 am
Location: Leicester

Postby ladders » Fri Jan 26, 2007 12:44 am

Thanks Mitch, only had time for a brief play but that seems to be working fine. Just out of interest so I can better understand what's going on, the function of most of the code you gave seems self-explanatory but what is the purpose of the line

If Target.Columns.Count <> 16 Then Exit Sub

Also, not sure if this kind of thing is something you use, but do you think using the appearance of 'Pending' is a reliable trigger to record this data, ie will it always appear, and if so, always for long enough to be picked up by the macro? would running the loop over a larger number of rows (say to a max of 16) or in multiple sheets with different markets simultaneously lead to unreliability?
ladders
 
Posts: 11
Joined: Wed Jan 17, 2007 1:43 am

Postby Mitch » Sat Jan 27, 2007 2:52 am

You can paste the code in the code window for each sheet you want to, unless you have a very fast refresh and loads of sheets I can't imagine it causing a problem. You can also increase the loop to cover more runners if you want to without altering reliability.
If you want to include all runners then make the loop read "For i = 5 to [F65536].End(xlUp).Row" which will run to the last row in the sheet (as long as you don't store anything else in col.F below the runners).

I'd guess that PENDING is as reliable an indicator as anything else, I personally don't use anything like this though.

"Target" is the range that has been altered on the sheet to fire the macro, so Target.Columns.Count is how many columns wide the changed area is. With triggered betting enabled, BA pastes the selections and prices first in one lump, then each row of betting data one at a time. This means that without that line of code, with for example 10 runners in the race, that the macro would get fired 11 times for each refresh which to me is unnecessary. The line of code prevents the macro running for all the single lines that are updated i.e. it will only run once per refresh.

I hope that makes sense. :?
User avatar
Mitch
 
Posts: 365
Joined: Sat Nov 19, 2005 12:28 am
Location: Leicester

Postby ladders » Sat Jan 27, 2007 1:20 pm

ok thanks for the explanation, i now understand why it was only working when connected to BA.

I've placed a few bets with it and the PENDING trigger seems to work every time. I aim to run this on quite a few markets, but a high refresh rate isnt necessary so it sounds like it'll be fine. :)
ladders
 
Posts: 11
Joined: Wed Jan 17, 2007 1:43 am

Postby Princerupert » Fri Feb 23, 2007 1:21 am

Hi Mitch

I have just been trying to copy your previous routine.

I am new to VBA.

I have a new spreadsheet, I go to the worksheet tab and right click to paste this code in.

However nothing happens.

I am useing excel 2000

Any help appreciated

regards

Rupert


Private Sub Worksheet_Change(ByVal Target As Range)

Cells(5, 26) = "Help"

If Target.Columns.Count <> 16 Then Exit Sub
Application.EnableEvents = False

MsgBox Cells(3, 17)



For i = 5 To 14
'my pending value value is in Q3
'I am trying to put f5 etc into z5
If Cells(3, 17) = "PENDING" Then Cells(i, 26) = Cells(i, 6)
Next i

Application.EnableEvents = True

End Sub
Princerupert
 
Posts: 4
Joined: Sun Nov 12, 2006 11:08 am

Postby Mitch » Sat Feb 24, 2007 12:37 am

I might be misunderstanding what the problem is, but cells(3,17) will never have "PENDING" in. Should that line be cells(i,17)?
User avatar
Mitch
 
Posts: 365
Joined: Sat Nov 19, 2005 12:28 am
Location: Leicester

Postby Princerupert » Sat Feb 24, 2007 9:02 pm

Hi Mitch

it seems as if you have to log out of excel for the vba code to start to be triggered.

its all working now.

only problem left is how to deal with the time in d2 properly
I wish to convert it into seconds

Thanks

Rupert
Princerupert
 
Posts: 4
Joined: Sun Nov 12, 2006 11:08 am

Postby MarkRussell » Sat Feb 24, 2007 9:22 pm

Hi

if you want to display hh:mm:ss as just seconds, choose a different cell and use the formula =60*60*24*D2
Make sure you change the format of the new cell to number with zero decimal places.

Hope this helps.

Regards,
Mark
User avatar
MarkRussell
Site Admin
 
Posts: 1787
Joined: Tue Feb 20, 2007 6:38 pm
Location: Birmingham


Return to Help

Who is online

Users browsing this forum: No registered users and 122 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.