Combine a Sub Worksheet_Change with Sub Worksheet_Calculate

  • I have two Subs that I need to incorporate. I can run one or the other, but not together? Any assistance gratefully acknowledged.


  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    Hi Roy, thanks for your reply. Bet Angel is software connected to a Betting Exchange (Betfair), so unless you are a subscriber , it won't work for you. The information from Betfair is relayed to a excel work sheet modified to suit (Bet Angel worksheet). I have an attached worksheet (Price Order) which, in the main, duplicates what the Bet Angel sheet displays, but has user defined functions to take that information and trigger a bet back to the BA sheet. The sheet I wish to copy though (the Change Sub) is the Price Order sheet and paste to Sheet 1. Copy_Race is the macro. I just can't understand why, if I put the Change code into the Price Order sheet, why it won't trigger? There are manual trigger buttons there to facilitate, but I need this to run Auto. I'm told the Change Sub has to reside in the Bet Angel sheet to work but there's a conflict with the Calculate Sub. Beyond me! Anyway, no one on the Bet Angel forum can resolve it for me, hence this post. I've attached the workbook anyway. The VB doesn't show the Change Sub that I had in my first post, only because it doesn't work with the Calculate Sub present. The Change sub is fired by a timer reaching 0 and cell Y5 on the Price Order sheet displays "YES". You can manually paste in "YES" to duplicate a Live connection. Good luck, but if too difficult, I understand :) Sorry....but how do you attach a file? Can't see any way?

  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    I only wanted to see which sheet the code is contained i. It is Bet Angel so the code doesn't need to use a With Statement because it will default to that sheet unless you specify a different sheet.


    Code
    With ThisWorkbook.Sheets("Bet Angel")


    In the example your code is in the Sheet named Bet Angel. See if this works


  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    There are a whole series of problems with this code:

    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
        If .Address = "$V$4" Then
            If .TimeValue = "-00:00:05" Then
                Call Copy_Race
        End If
    End Sub


    1) The code is contained in a standard code module, but needs to be in a worksheet code module
    2) Any references starting with a . must be contained inside a With ... End With section of code
    3) TimeValue is a function, not a property of an object (whatever that object is supposed to be - see (2) above)
    4) You can't have a negative timevalue
    5) You have two IF statements and only one END IF.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    Yes you're right Batman, but that code was a remnant from a past failed attempt and was defunct. I should remove it. Whether it's there or not, I don't believe it has a bearing on the case at hand. But you are being thorough to spot it, thanks......But thinking about past failed attempts, do you think that bit of code if corrected and time set at 00:00:00 could replace some of Roy's original code?

  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    What is this?


    Sub W_Change


    Where have you pasted the code?


    Attach the workbook that has the new code

  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate



    Roy, there is NO new code. It was a remnant left in Module 1 of the file I previously sent.

  • Re: Combine a Sub Worksheet_Change with Sub Worksheet_Calculate


    There seems to be a problem in both event procedures. Having removed the With ... End With statements, any range (or other property) references starting with . should also have that character removed

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!