VBA counting help

Please post any questions regarding the program here.

Moderator: 2020vision

VBA counting help

Postby Captain Sensible » Wed Aug 16, 2006 12:39 pm

Can any of the vba coders see whats wrong with the code below ?

I had it working OK on my PC then it decided to stop once I'd pasted it in another sheet just using Alt F11, is there anything I need to do to get VBA code working when placed into new sheets - previously I've just copied them straight in and they run ok. #

Basically it's meant to add 1 to C7 everytime C5 changes to 1.

Private Sub Worksheet_Calculate()
Static MyMarket As Variant
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
If [C5].Value = MyMarket Then
GoTo Xit
Else
If [C5].Value = 1 Then
mycount = [C7].Value + 1
[C7].Value = mycount
End If
End If
Xit:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Postby GeorgeUK » Wed Aug 16, 2006 3:07 pm

Have you given a value to MyMarket?

Can't see anything else it might be.
(Unless it's not in the sheet code but in a macro)
previously known as Gaseous (on the betfair forum)
User avatar
GeorgeUK
 
Posts: 315
Joined: Sat Nov 19, 2005 10:18 pm
Location: Scotland

Postby Captain Sensible » Wed Aug 16, 2006 6:53 pm

How do I give a value to my market, I just copied it from some code previously posted on her. Worked ok in one of those sheets. So I guess the value for mymarket must have been in there somewhere :(

Thanks
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Postby GeorgeUK » Wed Aug 16, 2006 8:38 pm

Was there another macro on the sheet you copied this from?

Possibly public - so that all code could use the range that this referred to?

Should be able to do CTRL+F and search the entire project of your other workbook
previously known as Gaseous (on the betfair forum)
User avatar
GeorgeUK
 
Posts: 315
Joined: Sat Nov 19, 2005 10:18 pm
Location: Scotland

Postby a1ehouse » Wed Aug 16, 2006 9:46 pm

I have just pasted the exact code in VBA Editor, put a 1 in C5, a 1 in C7, then pressed F5 to run the macro while in VBA editor and it works fine. Are you sure the Worksheet_Calculate macro is being fired?
...it maekesh me do a shecks wee...
Image
User avatar
a1ehouse
 
Posts: 69
Joined: Wed Apr 05, 2006 9:06 pm
Location: The Playboy Mansion

Postby Captain Sensible » Wed Aug 16, 2006 9:51 pm

" Are you sure the Worksheet_Calculate macro is being fired"

how would I know when it's being fired - I had it working OK before but now it won't for some unkonown reason. It was basically a hack of code posted on here before that clears the cell values when switching market on auto select

Private Sub Worksheet_Calculate()
Static MyMarket As Variant
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
If [A1].Value = MyMarket Then
GoTo Xit
Else
MyMarket = [A1].Value
Range(Cells(5, 17), Cells(100, 21)).Value = ""
End If
Xit:
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
End Sub
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Postby a1ehouse » Wed Aug 16, 2006 9:54 pm

Add the line MsgBox "hello!" after the line
Private Sub Worksheet_Calculate()

If you use Private Sub Worksheet_Change(ByVal Target As Range) it works
...it maekesh me do a shecks wee...
Image
User avatar
a1ehouse
 
Posts: 69
Joined: Wed Apr 05, 2006 9:06 pm
Location: The Playboy Mansion

Postby Captain Sensible » Wed Aug 16, 2006 10:19 pm

Thanks alehouse the message box thingy doesn't work on calculate but does on change.

Only problem with change is that it doesn't recognise when the cell has changed from 1 to 1 it'll still count and not go to exit. When the calculate one worked it'd not add another 1 if the cell changed from 1 to 1 as it went to exit
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Postby a1ehouse » Wed Aug 16, 2006 10:24 pm

Calculate only really works when you've formulae on the sheet

What happens when you put a formula on the sheet e.g. =Now()
...it maekesh me do a shecks wee...
Image
User avatar
a1ehouse
 
Posts: 69
Joined: Wed Apr 05, 2006 9:06 pm
Location: The Playboy Mansion

Postby Captain Sensible » Wed Aug 16, 2006 11:56 pm

K, thanks alehouse works fine when I have a calculation in cell C5 something like C5=D5+E5

Thanks for the help.
User avatar
Captain Sensible
 
Posts: 2883
Joined: Sat Nov 19, 2005 2:29 pm

Postby GeorgeUK » Thu Aug 17, 2006 12:04 am

on your original code you had
If [C5].Value = MyMarket Then

If cell C5 is the same as MYMarket value...

In the other example you gave, it had the line
MyMarket = [A1].Value

So MyMarket had a value. (But is still empty the first time it appears in the code)

The Worksheet_Calculate event will run every time a calculation is made, so your code will run if there is a formula on your sheet that changes (eg if a formula is influenced by the odds, every time the odds change the event will run)
previously known as Gaseous (on the betfair forum)
User avatar
GeorgeUK
 
Posts: 315
Joined: Sat Nov 19, 2005 10:18 pm
Location: Scotland

Postby GeorgeUK » Thu Aug 17, 2006 9:39 am

Just ignore me.

Giving bum advice :oops:

I thought the excel variables were Dim, Private and Public. With MyMarket needing to be a Public variable so it retained it's value the next time the code ran. This is what static does - so i was only correct for the first time the code is ran and MyMarket won't have a value assigned.

Sorry about that
:oops: :oops: :oops: :?
previously known as Gaseous (on the betfair forum)
User avatar
GeorgeUK
 
Posts: 315
Joined: Sat Nov 19, 2005 10:18 pm
Location: Scotland

Postby a1ehouse » Thu Aug 17, 2006 12:48 pm

Get to bed earlier G! :lol:
...it maekesh me do a shecks wee...
Image
User avatar
a1ehouse
 
Posts: 69
Joined: Wed Apr 05, 2006 9:06 pm
Location: The Playboy Mansion


Return to Help

Who is online

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

cron