Amending Gary's code for coupon markets

Please post any questions regarding the program here.

Moderator: 2020vision

Amending Gary's code for coupon markets

Postby xraymitch » Fri Dec 28, 2012 1:13 pm

Hi Gary,

I am trying to amend your code and have added the offset r so that it hopefully can be used in coupon markets.

Not sure what I am doing so any advice on improving this code would be greatly appreciated. I suspect I should be using some kind of "Do Whilst true loop" instead of a "For Next".

Thanks for your time.

xraymitch 8)


PS. There are 12 soccer matches today so I am using the code below to experiment and see what happens. So far there are no freezes which is at least encouraging.

Private Sub Worksheet_Change(ByVal Target As Range)

For r = 0 To 110 Step 10

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

If Cells(2 + r, 5) = "In Play" Then
If Cells(1 + r, 27) = "" Then Cells(1 + r, 27) = Cells(2 + r, 3)
If Cells(1 + r, 27) <> "" Then Cells(1 + r, 28 ) = DateDiff("s", Cells(1 + r, 27), Cells(2 + r, 3))
End If

If Cells(2 + r, 5) <> "In Play" And Cells(2 + r, 6) <> "Suspended" Then
Cells(1 + r, 27) = ""
Cells(1 + r, 28 ) = ""
End If

Application.EnableEvents = True
End If

Next r

End Sub
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Postby xraymitch » Fri Dec 28, 2012 3:17 pm

Have to say that so far on the 12 matches it has worked flawlessly.

Not sure how it will cope with 4 times that number or more on a regular day though.

Still unclear how to calculate the number of matches automatically.

:roll:
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Postby Captain Sensible » Fri Dec 28, 2012 8:01 pm

Don't think it's too hard for excel to find the last column used , then just do some simple maths to work out how many markets and use that value when you're calculating


Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row


For r = 0 To LastRow Step 10

Maybe you'll need to add some number or other to LastRow just to get it to a multiple of 10 I don't use the coupons so no idea how they're laid out
User avatar
Captain Sensible
 
Posts: 2923
Joined: Sat Nov 19, 2005 2:29 pm

Postby xraymitch » Mon Dec 31, 2012 9:35 pm

Thanks Captain - you are always there for me :)

Prior to seeing this evening your post I had thought the following code was perfect and will cover 100 matches so no need to know the last row.

I am confident the logic is correct, but somewhere my implementation of the coding is faulty and after two hours I have given up trying for the moment.

As there is no Half Time Coupon I am using the Match and Half Time Odds Coupon. The spreadsheet layout, providing you initiate the coupon before the Half Time Odds Market is closed, means that Match Odds are at row 1, Half Time odds at row 11 giving you:

Row 1 Match Odds
Row 11 Half Time Odds
Row 21 Match Odds
Row 31 Half Time Odds

and so on. Hence when R mod 20 = 0 Match Odds Market, and when R mod 20 = 10 Half Time Market.

When I run the code I get a Compile Error - Next Without For. I thought I could enclose all the code inside the For Next Loop but it seems not.

When you have a moment can you amend my code and make it work.

Private Sub Worksheet_Change(ByVal Target As Range)

'Start of Match and End of First Half using Match and Half Time Odds Coupon

For r = 0 To 2000 Step 10

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

'End of First Half using Match and Half Time Odds Coupon


If r Mod 20 = 10 Then

If Cells(2 + r, 5) = "In Play" And Cells(2 + r, 6) = "Closed" Then
If Cells(1 + r, 27) = "" Then Cells(1 + r, 27) = Cells(2 + r, 3)
If Cells(1 + r, 27) <> "" Then Cells(1 + r, 28 ) = DateDiff("s", Cells(1 + r, 27), Cells(2 + r, 3))
End If

If r Mod 20 = 10 Then

If Cells(2 + r, 5) <> "In Play" And Cells(2 + r, 6) <> "Closed" Then
Cells(1 + r, 27) = ""
Cells(1 + r, 28 ) = ""
End If

'Start of Match using Match and Half Time Odds Coupon


If r Mod 20 = 0 Then

If Cells(2 + r, 5) = "In Play" Then
If Cells(1 + r, 27) = "" Then Cells(1 + r, 27) = Cells(2 + r, 3)
If Cells(1 + r, 27) <> "" Then Cells(1 + r, 28 ) = DateDiff("s", Cells(1 + r, 27), Cells(2 + r, 3))
End If

If r Mod 20 = 0 Then

If Cells(2 + r, 5) <> "In Play" And Cells(2 + r, 6) <> "Suspended" Then
Cells(1 + r, 27) = ""
Cells(1 + r, 28 ) = ""
End If

Application.EnableEvents = True


End If

Next r

End Sub

Thanks for the "LastRow" code very helpful and adds greatly to my understanding of VBA. So far all I can do with it is use it as a macro as in:

Sub findlastrow()
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
End Sub

As an example, can you show me how I could use that in my included code.

Thanks again for your input and all the very best for the New Year 8)
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK

Postby xraymitch » Tue Jan 01, 2013 1:03 pm

Hi Captain,

Got side tracked by the compile error- should have checked the HELP straight away. I forgot each IF THEN needed an END IF... :oops:

All the best for the New Year.

8)
xraymitch
 
Posts: 410
Joined: Wed Jun 25, 2008 7:06 am
Location: UK


Return to Help

Who is online

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