Macro Help

Please post any questions regarding the program here.

Moderator: 2020vision

Macro Help

Postby mak » Sun Dec 13, 2009 10:20 am

I want to close a workbook when my exposure (cell L2) reach a limit lets say -300

I am trying to use the following code but nothing is happening...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Cells(2, 12).Value >= -1040 Then
Workbooks("makis1.xls").Close savechanges:=False
End If
End If
End Sub


Can someone help please?
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Re: Macro Help

Postby mak » Sun Dec 13, 2009 10:21 am

mak wrote:I want to close a workbook when my exposure (cell L2) reach a limit lets say -300

I am trying to use the following code but nothing is happening...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Cells(2, 12).Value >= -300 Then
Workbooks("makis1.xls").Close savechanges:=False
End If
End If
End Sub


Can someone help please?
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Re: Macro Help

Postby mak » Sun Dec 13, 2009 10:24 am

mak wrote:
mak wrote:I want to close a workbook when my exposure (cell L2) reach a limit lets say -300

I am trying to use the following code but nothing is happening...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Cells(2, 12).Value >= -300 Then
Workbooks("makis1.xls").Close savechanges:=False
End If
End If
End Sub


Can someone help please?


Sorry I have to add that I am using excel 2007 and the workbook name is makis1.xlsm

I have tried with .xlsm also but no luck yet...
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby Ian » Sun Dec 13, 2009 11:07 am

Should be <= -300 ?
Ian
 
Posts: 834
Joined: Sat Nov 19, 2005 8:35 am
Location: Birmingham

Postby osknows » Sun Dec 13, 2009 11:18 am

try

Code: Select all
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Columns.Count = 16 Then
If Cells(2, 12).Value >= -1040 Then
Thisworkbook.Close False
End If
End If
End Sub



ActiveWorkbook.Close False
' closes the active workbook without saving any changes

ActiveWorkbook.Close True
' closes the active workbook and saves any changes

ActiveWorkbook.Close
' closes the active workbook and lets the user decide if
' changes are to be saved or not
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby mak » Sun Dec 13, 2009 1:06 pm

Os thanks,
but still the workbook remains open

I am running also a macro with on time method where every 20 sec perform
a calculation and place some bets

Do you believe that it has to do with this?

** I also tried in another cell where if it is YES then workbook close & though the cell returns YES the workbook remains open.
mak
 
Posts: 1086
Joined: Tue Jun 30, 2009 8:17 am

Postby osknows » Sun Dec 13, 2009 1:18 pm

Did you try Ian's correction?

I missed it too :) It should be

If Cells(2, 12).Value <= -1040 Then
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am

Postby osknows » Sun Dec 13, 2009 1:24 pm

mak wrote:** I also tried in another cell where if it is YES then workbook close & though the cell returns YES the workbook remains open.


Sorry mis-read this bit earlier. Not sure what it is then? Send me a PM with link if you like and I'll have a look
User avatar
osknows
 
Posts: 946
Joined: Wed Jul 29, 2009 12:01 am


Return to Help

Who is online

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