Vba Help :)

Please post any questions regarding the program here.

Moderator: 2020vision

Vba Help :)

Postby mak » Tue May 25, 2010 12:58 pm

I have set bA to autoselect markets 1 min before the off

How can I call 2 macros (MyMacro1 - MyMacro2) just once when the market change?
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 1:24 pm

maybe something similar to this - note cell Q1 in excel must equal Y to run the code

Code: Select all

Dim nextracetrigger As Integer


Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count = 16 Then

Application.EnableEvents = False

       
    'forward quick pick race on after race ended - NOTE CAN BE TURNED ON/OFF USING Y IN CELL Q1
    With ThisWorkbook.Sheets(Target.Worksheet.Name)
   
    'forward market if market suspended
    If .Range("E2").Value = "In Play" And .Range("F2").Value = "Suspended" And UCase(.Range("Q1").Value) = "Y" And nextracetrigger = 0 Then
        nextracetrigger = 1
        lastrace = .Range("A1").Value
        .Range("Q2").Value = -1
       
    'forward market if market closed
    ElseIf .Range("F2").Value = "Closed" And UCase(.Range("Q1").Value) = "Y" And nextracetrigger = 0 Then
        nextracetrigger = 1
        lastrace = .Range("A1").Value
        .Range("Q2").Value = -1
       
    'catches last closed market at end of day and updates balance
    ElseIf .Range("F2").Value = "Closed" And UCase(.Range("Q1").Value) = "Y" And nextracetrigger = 1 Then
        nextracetrigger = 2
        .Range("Q2").Value = -6
       
    'catches last closed market at end of day and resets refresh rate to 1
    ElseIf .Range("F2").Value = "Closed" And UCase(.Range("Q1").Value) = "Y" And nextracetrigger = 2 Then
        nextracetrigger = 2
        .Range("Q2").Value = 1
   
    End If
   
    If lastrace <> .Range("A1").Value Then
        nextracetrigger = 0
       
        'macros to run when event changes
        MyMacro1
        MyMacro2
    End If
   
    End With
   
   
Application.EnableEvents = False
end if

end sub
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby osknows » Tue May 25, 2010 1:27 pm

sorry add 'lastrace' also with the other DIM statement

Code: Select all
Dim nextracetrigger As Integer
Dim lastrace As String
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby mak » Tue May 25, 2010 1:44 pm

Os thanks but is not working

Please note that I autoselect markets and I don't want to go in play...

I thought it could be an easy thing to do...
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 1:57 pm

Code: Select all
Dim lastrace As String

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count = 16 Then

Application.EnableEvents = False

    If lastrace <> ThisWorkbook.Sheets(Target.Worksheet.Name).Range("A1").Value Then
       
        'macros to run when event changes
        MyMacro1
        MyMacro2
    End If
   
    End With
   
   
Application.EnableEvents = False
End If

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

Postby mak » Tue May 25, 2010 2:12 pm

Sorry, maybe i am doing something wrong, but it doesn't work also

I deleted -- End with
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby mak » Tue May 25, 2010 3:57 pm

Os
is working only when i first log BA to excel
afterwards is not calling the macros
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 4:42 pm

sorry! This should work
Code: Select all
Dim lastrace As String

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count = 16 Then

Application.EnableEvents = False

    If lastrace <> ThisWorkbook.Sheets(Target.Worksheet.Name).Range("A1").Value Then
        lastrace = ThisWorkbook.Sheets(Target.Worksheet.Name).Range("A1").Value Then
        'macros to run when event changes
        MyMacro1
        MyMacro2
    End If

   
Application.EnableEvents = False
End If

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

Postby mak » Tue May 25, 2010 4:48 pm

not yet
the Red line is red also in the code...


Dim lastrace As String

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Columns.Count = 16 Then

Application.EnableEvents = False

If lastrace <> ThisWorkbook.Sheets(Target.Worksheet.Name).Range("A1").Value Then
lastrace = ThisWorkbook.Sheets(Target.Worksheet.Name).Range("A1").Value Then
'macros to run when event changes
MyMacro1
MyMacro2
End If


Application.EnableEvents = False
End If

End Sub
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 4:57 pm

remove then on the red line. That's what you get trying to write code direct onto a forum :)
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby mak » Tue May 25, 2010 5:04 pm

today is not my day
still can't figure it out

still working only one time :shock:
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 5:07 pm

:oops: :oops: :oops:
try changing the last Application.EnableEvents = False

to Application.EnableEvents = true
:oops: :oops: :oops: :oops: :roll:
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby mak » Tue May 25, 2010 5:18 pm

that's better

but now
it keep firing mymacros without stopping... :? :? :?
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Tue May 25, 2010 6:33 pm

I'm not sure? If you're happy to send me your code or worksheetI'll have a look

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

Postby mak » Tue May 25, 2010 6:55 pm

Os
you've got mail...
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Next

Return to Help

Who is online

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