Clearing status cells - Excel Macros

Post Reply
Nero Tulip
Posts: 686
Joined: Wed Apr 15, 2009 5:29 pm

PeterLe wrote:Thanks Guys
Really appreciate your help with this...
I'm not an Excel wizard, but I'm going to have a go. (Think I'll transfer all the funds except say £20, into the Aus Wallet Just in case!!! )
Regards
Peter
Better to be safe to begin with. The BA chaps leave it this way for a reason - to make sure it's safe to use. This macro is dangerous if you don't have the right money management stuff in the rest of your sheet.

Also, this will only clear the status cell relating to selection one in the market. (In case that wasn't obvious! apologies) To do the others you have to copy and paste the same and rename the cells for each row.
User avatar
TheTub
Posts: 267
Joined: Thu Mar 26, 2009 7:53 pm
Location: Nottinghamshire

Yup that works.

I tried this method in the past and couldn't get it working. Must have made a simple error.

Thanks for the code.
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

This link might give others help if they are looking for something similar.

http://www.ozgrid.com/VBA/run-macros-change.htm
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

Hi Nero
Been experimenting with this...and at the risk of being a pain..can I ask for more advice?? ! (",)
Following on from the user "BetAngel" post...where they state that the excel refresh state is slower when having many worksheets open.. I really just want to have the single worksheet file open..(using Guardian to switch markets). Within the worksheet I have created a macro called "Clear_Status"

I can get your code working... but rather than it constantly clearing the contents.. I only want to run the code Just once, Ideally right at the end of the race when it displays "Suspended"..

So I can either use your code..(modified in some way) Or I believe that it is possible to call a Macro from within VBA when a cell displays a certain string..?

If you are able to help..could you explain how I do it in easy steps??! (Still getting the hang of Macros and VBA)

Thank you
regards
Peter
hmw
Posts: 7
Joined: Wed Apr 15, 2009 9:58 pm

This is the code I use to reset the status everytime a bet has been placed; it's not a macro, it's code triggered by the worksheet_calculate event:

Code: Select all

Private Sub Worksheet_Calculate()
Dim i As Integer
For i = 9 To 67 Step 2
    If Range("O" & i).Value = "PLACED" Then _
    Range("O" & i).ClearContents
Next i
End Sub
And you could simply wrap this in an IF statement...

Code: Select all

If Range("H1").Value = "Suspended" Then
    For i = 9 To 67 Step 2
        If Range("O" & i).Value = "PLACED" Then _
        Range("O" & i).ClearContents
    Next i
End If
The code should be in the module described below by Nero Tulip » Thu Apr 16, 2009 5:44 pm
PeterLe
Posts: 3715
Joined: Wed Apr 15, 2009 3:19 pm

Thanks HMW
That looks a good way of doing it.
I'll have a play around with it.
I have decided to learn VBA...but a Dummys guide yesterday and another book on its way from Amazon..! I certainly have the incentive to learn VBA...and its surprising how quickly you can learn stuff when you need to!
In the meantime, I may ask some very basic questions, but they will get less as time goes by..I am a great believer that you get out of something what you put in...
Thanks for bearing with me!
Regards
Peter
dogform
Posts: 53
Joined: Fri Sep 11, 2009 12:27 pm

I am using the code pasted below and originally kindly posted by "hmw" to clear the status field when the market is indicated as suspended via cell H1.


Private Sub Worksheet_Calculate()
Dim i As Integer
If Range("H1").Value = "Suspended" Then
For i = 9 To 67 Step 2
If Range("O" & i).Value = "PLACED" Then _
Range("O" & i).ClearContents
Next i
End If
End Sub


I would like to be able to clear the status field (column "O") for other circumstances. For example, I wish to place a back bet with a tick offset incorporating a fill or kill and stop loss. If I understand the process correctly, the status field, "O", will show possible values of PENDING, PLACED, CANCELLED.

I wish to be able to automatically clear the status field "O" if the values are PLACED or CANCELLED or any other values except PENDING and the market has not been suspended (H1)and is not In Play (G1). This should allow repeated firing of the bet trigger unless it gets to the point where my other criteria controlling the arming and firing of the trigger stop it firing.

Any help with the code greatly appreciated as my VBA skills are pretty much non existent.

Thx & Rgds
Dog
JacoboPolavieja
Posts: 91
Joined: Thu Sep 10, 2009 6:00 pm

This is embarrasing but after having searched for a while I can't get it working...

I copy hmw's code into a new module. The problem is it doesn't automatically run. If from the VBA screen I run it it works ok. If I don't do that manually it doesn't clear the cells... What am I doing wrong? How do I enable the macro to always run?

Thanks! Cheers!
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

The code needs to go in a worksheet, not a module.

Select the sheet tab and right click. Select "view code"
and pop it in there.

Nigel.
JacoboPolavieja
Posts: 91
Joined: Thu Sep 10, 2009 6:00 pm

Hi nigelk and thanks for helping.

I've done what you said and it remains the same... no automatic action but works well when manually run :roll:.

Any other ideas? Thanks!
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

It can only be one of two things really

Either you have no formulas in your worksheet (unlikely), or it's the conditions not being met that's stopping it.

Put this in

Private Sub Worksheet_Calculate()
Dim i As Integer

For i = 9 To 67 Step 2

Range("O" & i).ClearContents
Next i

End Sub

now put anything in O9 and then in another cell put a calculation: =2 will do

O9 should now be clear?
JacoboPolavieja
Posts: 91
Joined: Thu Sep 10, 2009 6:00 pm

Hi nigelk,

Thanks for taking the time helping me out with this.

I did what you recommended with the same effect... it works as expected if I hitthe "play" button from the VBA interface, but doesn't automatically behave like that without my interaction.

The condition are met as the only condition I have is O9, O11, etc having the word "FAILED" which it clears correctly when run manually...

Pretty weird thing. I'm using Excel 2010 and I've put this in a book with macros enabled. Any other idea on how to determine where this may be coming from?

Thank you. Cheers!
nigelk
Posts: 469
Joined: Wed Apr 15, 2009 11:00 pm

It is the sheet, not a module?
JacoboPolavieja
Posts: 91
Joined: Thu Sep 10, 2009 6:00 pm

nigelk wrote:It is the sheet, not a module?
Yep! I've put it in the exact sheet, in the Worksheet... nothing happens automatically.

I've tried to look for anything regarding automatically running macros, but it all seems normal.

Thanks a lot!
JacoboPolavieja
Posts: 91
Joined: Thu Sep 10, 2009 6:00 pm

I really don't get it...

After thinking for a while I thought it could be an issue with the security settings for macros. I went to the Excel's "Trust Center" and enabled everything (which I know is a risk). Still... all goes fine when run manually but it does nothing if I write on a cell it should automatically clear.

I hate these things! It has to be a silly one but I can't find it!

Just needed to speak out the desperation... hehe!
Post Reply

Return to “Tips and tricks”