Basic VB help

Please post any questions regarding the program here.

Moderator: 2020vision

Basic VB help

Postby lutpoy28 » Thu Jan 24, 2008 11:06 pm

Hi

Could someone please advise of the command required to stamp the value found from a basic IF such as below once the IF statement has been met.

i.e once IF is met retain the value

Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4) = Sheet1.Cells(4, 26) Then
Sheet1.Cells(5, 26) = Sheet1.Cells(5, 6)
Else
Sheet1.Cells(5, 26) = ""
End If


End Sub
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby KevinTHFC » Thu Jan 24, 2008 11:36 pm

I think you need to change it like this-

Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4).value = Sheet1.Cells(4, 26).value Then
Sheet1.Cells(5, 26).value = Sheet1.Cells(5, 6).value
Else
Sheet1.Cells(5, 26).value = ""
End If


End Sub
KevinTHFC
 
Posts: 72
Joined: Fri Aug 25, 2006 9:08 pm

Postby lutpoy28 » Thu Jan 24, 2008 11:52 pm

Thanks but still does not retain value, i know nothing about vb so mere novice. At present criteria is met and value flashes up in cell but then dissapears as cells(2,4) is not a constant and is ever changing by the second.
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby lutpoy28 » Fri Jan 25, 2008 1:28 am

I came up with this but i know its not right becuase if i have more than 1 in a row the screen just keeps repeating the macro and flashes, click escape and select end and result is correct but its not ending itself.

Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4) = Sheet1.Cells(4, 26) Then
Sheet1.Cells(5, 6).Select
Selection.Copy
Sheet1.Cells(5, 26).Select
ActiveSheet.Paste
End If



If Sheet1.Cells(2, 4) = Sheet1.Cells(4, 27) Then
Sheet1.Cells(5, 6).Select
Selection.Copy
Sheet1.Cells(5, 27).Select
ActiveSheet.Paste
End If

End sub
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby Ian » Fri Jan 25, 2008 8:46 am

You need to set up a marker so that the copy is only done once, something like this ...

Dim Flag As Boolean


Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 26).Value And Flag = False Then
Sheet1.Cells(5, 26).Value = Sheet1.Cells(5, 6).Value
Flag = True
Else
Sheet1.Cells(5, 26).Value = ""
End If


End Sub
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby lutpoy28 » Fri Jan 25, 2008 9:47 am

Thanks

If I ave multiple subs how do i tell it to RUN all subs rather than just the sub ive highlighted, do i need a command or something in between them.

Private Sub Worksheet_Calculate10()

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 26).Value And Flag = False Then
Sheet1.Cells(5, 26).Value = Sheet1.Cells(5, 6).Value
Flag = True
Else
Sheet1.Cells(5, 26).Value = ""
End If

End Sub



Private Sub Worksheet_Calculate9()

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 27).Value And Flag = False Then
Sheet1.Cells(5, 27).Value = Sheet1.Cells(5, 6).Value
Flag = True
Else
Sheet1.Cells(5, 27).Value = ""
End If
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby Ian » Fri Jan 25, 2008 11:27 am

You don't need multiple - just put all the code in one worksheet_calculate.

Looks like you will need multiple flags though .. one for each IF statement.

You will also probably need to have some code that puts all the flags to false at some point eg. when you change market.
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby lutpoy28 » Fri Jan 25, 2008 11:55 am

Excuse my ignorance but as say never used VB before, what do you mean by multiple flags, if the below wrong then as only records the data for first IF

Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 26).Value And Flag = False Then
Sheet1.Cells(5, 26).Value = Sheet1.Cells(5, 6).Value
Flag = True
Else
Sheet1.Cells(5, 26).Value = ""
End If


If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 27).Value And Flag = False Then
Sheet1.Cells(5, 27).Value = Sheet1.Cells(5, 6).Value
Flag = True
Else
Sheet1.Cells(5, 27).Value = ""
End If

End Sub
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby lutpoy28 » Fri Jan 25, 2008 11:57 am

similar to this ?

Havent got a clue how you clear a flag so will delete manually, lol



Private Sub Worksheet_Calculate()

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 26).Value And Flaga = False Then
Sheet1.Cells(5, 26).Value = Sheet1.Cells(5, 6).Value
Flaga = True
Else
Sheet1.Cells(5, 26).Value = ""
End If


If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 27).Value And Flagb = False Then
Sheet1.Cells(5, 27).Value = Sheet1.Cells(5, 6).Value
Flagb = True
Else
Sheet1.Cells(5, 27).Value = ""
End If

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 29).Value And Flagc = False Then
Sheet1.Cells(5, 29).Value = Sheet1.Cells(5, 6).Value
Flagc = True
Else
Sheet1.Cells(5, 29).Value = ""
End If

If Sheet1.Cells(2, 4).Value = Sheet1.Cells(4, 31).Value And Flagd = False Then
Sheet1.Cells(5, 31).Value = Sheet1.Cells(5, 6).Value
Flagd = True
Else
Sheet1.Cells(5, 31).Value = ""
End If

End Sub
lutpoy28
 
Posts: 29
Joined: Wed Oct 24, 2007 4:29 pm

Postby Ian » Fri Jan 25, 2008 12:21 pm

Yes something like that. Define each flag at the top eg

Dim flaga as Boolean
Dim flagb as Boolean etc. etc.
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham


Return to Help

Who is online

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