Why does this simple code not work?

Please post any questions regarding the program here.

Moderator: 2020vision

Why does this simple code not work?

Postby Smokin Joe » Tue Jun 03, 2008 3:30 pm

My code reads as follows:

Option Explicit

Dim wb1 As Workbook
Dim ws1 As Worksheet

Private Sub Worksheet_Change(ByVal Target As Range)
' Only process whole updates
If Target.Columns.Count <> 16 Then Exit Sub

' Set-up workbook variables
Set wb1 = ThisWorkbook
Set ws1 = wb1.Sheets("Sheet1")

' Stop any further updates until we have completed
Application.EnableEvents = False

' Check for "CANCELLED" in cell T5
If ws1.Range("T5").Value = "CANCELLED" Then
' Clear bet references
ws1.Range("T5:W5").ClearContents
End If

' Re-enable updates
Application.EnableEvents = True
End Sub



T5 currently reads "CANCELLED" yet T5:W5 have not been cleared.
The worksheet is named Sheet1.
The spreadsheet is still updating as the clock is still counting down.

Any ideas what is wrong?
Smokin Joe
 
Posts: 115
Joined: Sat May 31, 2008 6:25 am

Postby Smokin Joe » Tue Jun 03, 2008 4:15 pm

I restarted my PC and it worked (as I knew it should have done!!!)

Strange................
Smokin Joe
 
Posts: 115
Joined: Sat May 31, 2008 6:25 am

Postby PeteB » Tue Jun 03, 2008 4:16 pm

Put a breakpoint on the line
If ws1.Range("T5").Value = "CANCELLED" Then

and then see what happens - you'll be able to see if this code is being called, and if it is, what the value of ws1.Range("T5").Value is at this point

It may be that you should be testing ws1.Range("T5").Value2 rather than ws1.Range("T5").Value - or it may be that you need to make the strings the same length before testing - something like:
If left(ws1.Range("T5").Value, 10) = "CANCELLED" Then

But the breakpoint should give you the answer pretty quickly anyway
PeteB
 
Posts: 258
Joined: Tue May 23, 2006 12:13 pm

Postby PeteB » Tue Jun 03, 2008 4:17 pm

Ok good news :-)
PeteB
 
Posts: 258
Joined: Tue May 23, 2006 12:13 pm

Postby Smokin Joe » Tue Jun 03, 2008 4:41 pm

I am learning!!!!

The reason for the code not working is that I was amending the code at it would appear that I need to see application.enableevents = false before I perform any code changes.

Still we live and learn :roll:

Apologies for my ramblings.
Smokin Joe
 
Posts: 115
Joined: Sat May 31, 2008 6:25 am

Postby Smokin Joe » Tue Jun 03, 2008 4:42 pm

Thanks for your input Pete.
Smokin Joe
 
Posts: 115
Joined: Sat May 31, 2008 6:25 am


Return to Help

Who is online

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