+ Reply to Thread
Results 1 to 7 of 7

Trigger Macro on cell change by real time data

  1. #1
    Registered User
    Join Date
    01-04-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Trigger Macro on cell change by real time data

    Hi

    I receive real time stock data from my broker. I would like to trigger a macro ( say if stock value is > 5). My little research shows that many people suggested to use the a code with the worksheet_change trigger such as )see below. The worksheet_change is not initiated when the value changes via real time data. It work when I change the value manually or with a program but not if the change in the target cell is changes via incoming real time data. Any solutions? Many thanks!

    Please Login or Register  to view this content.
    Last edited by JosephP; 01-04-2013 at 09:39 AM. Reason: add code tags

  2. #2
    Forum Expert OllieB's Avatar
    Join Date
    12-20-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2007 (home) & 2010 (office)
    Posts
    1,542

    Re: Trigger Macro on cell change by real time data

    You may want to try creating a public function that receives the cell (or column) as a parameter. Whenever the input to the function changes (i.e. the cell value) the function gets automatically called as part of the calculation trigger.
    If you like my contribution click the star icon!

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trigger Macro on cell change by real time data

    you can also use the worksheet_calculate event and test the value against its previous value which you store in a static variable

    please note the code tags I added to your post and please learn to use them in future
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Trigger Macro on cell change by real time data

    pl see the attached file .Worksheet_SelectionChange event is used for sheet1.Reactivate the sheet and use it.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    01-04-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Trigger Macro on cell change by real time data

    Thanks so much for the suggestions but I think the problem is because excel internal events ( such as the cell changes from incoming data stock stream supplied by the Interactive Broker) are not triggered or recognized as a cell change/calculation but thats my guess so far ......

  6. #6
    Registered User
    Join Date
    10-07-2012
    Location
    Bonn, Germany
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Trigger Macro on cell change by real time data

    Hi,
    I had exactly the same problem, years ago even, but I could not recall the reason for that.

    Here comes an answer from the lovely city of Fukuoka and I fully agree:

    "Quote"
    The Change Event does not capture everything. In particular it does not capture changes that are the result of a re-calculation, and I am guessing that the way you are importing the data may fall into that category.

    I have grappled with this myself on several occasions, sometimes having to resort to putting the new data alongside the old, comparing the two (and taking any action I want if there are changes) then making the new data the old data . . . etc.
    "End Quote"

    So I use my workaround that I am used to and that's just it...

    Have a nice weekend,
    Wolfgang

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Trigger Macro on cell change by real time data

    I am very surprised if an rtd function doesn't trigger a calculate event but if it in fact doesn't you might perhaps be able to use the workbook's setlinkondata method

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1