+ Reply to Thread
Results 1 to 13 of 13

Show if cell is greater or smaller than previous value

  1. #1
    Registered User
    Join Date
    11-13-2009
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Show if cell is greater or smaller than previous value

    Hello,

    I have a DDE feed going into an Excel spreadsheet which gives me a share price in real-time. i.e the cell value is constantly changing.

    I would like to create a formula that tells me if the price is 'Rising' or 'Falling' based on the previous value, before it was updated.

    So, for example, if cell C4 said £1.00 and the the next price change changed cell C4 to £1.05 I would like cell C5 to say 'Rising' If the next price change was say to £1.04 I would like cell C5 to say 'Falling'.

    I thought I was OK with Excel, but I can't figure it out!

    Any suggestions as to how it can be done? Please help.

    Many thanks,

    Chris

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to show if a cell is greater or smaller than its previous value?

    You can declare a couple of public variables. Then use them in a Worksheet_change event macro.

    Each time the "watched" cell changes, public variable TWO value become public variable ONE value, public variable ONE value value becomes the new "watched" cell value.

    Then a simple equation against those two variable will tell if things are going up or down.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to show if a cell is greater or smaller than its previous value?

    1) Right-click on the sheet tab and select VIEW CODE
    2) Paste in this event macro:
    Please Login or Register  to view this content.
    3) Close the editor and save your sheet

    Now manually change the value in C4 or wait for your web query to do it and the C5 status will update automatically.
    Last edited by JBeaucaire; 11-13-2009 at 12:24 PM.

  4. #4
    Registered User
    Join Date
    11-13-2009
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: How to show if a cell is greater or smaller than its previous value?

    It's hard to know which impresses me the most: The speed, or the quality of your reply.

    Thank you.

    I have to go out now. As soon as I have the opportunity, I will let you know how I got on.

    Thanks again.

  5. #5
    Registered User
    Join Date
    11-13-2009
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: How to show if a cell is greater or smaller than its previous value?

    It works well with manually entered in data.

    The DDE share feed has stopped until markets open again on Monday. So cannot test with live data until then.

    Will let how I get on Monday. Meantime have a great weekend.

    Chris

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to show if a cell is greater or smaller than its previous value?

    It should operate the same way. I've used ws_change events in conjunction with web queries before and they work great together.


    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].



    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated)

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How to show if a cell is greater or smaller than its previous value?

    A DDE update will not invoke the Change event, only the Calculate event (like other formulae).

    Given a calculation event can be invoked by actions other than the update of the DDE I would suggest using a Static variable in the Calculate event such that you can compare pre & run-time values of DDE so as to determine alteration and subsequently, when applicable, direction.

    EDIT: thread below has different final requirement but same premise - ie capturing DDE change and acting accordingly, does outline basic premise of using Static variable etc...
    http://www.excelforum.com/excel-prog...her-sheet.html
    Last edited by DonkeyOte; 11-13-2009 at 03:14 PM. Reason: added link

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: How to show if a cell is greater or smaller than its previous value?

    Don, the macro given above won't work if it's changed to a Worksheet_Calculate event instead? I've never used DDE so I can't test that.

  9. #9
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: How to show if a cell is greater or smaller than its previous value?

    There is no Target.

    You would want a Static variable which at run time will be the "last known value" for the given Range, then compare current to Static - if it's changed then you know the cell in question has recalculated at which point you can conduct whichever acts are required before setting the Static variable to be the current value (toggling events appropriately).

    In this instance given a DDE can quite feasibly update without changing (ie same price) the fact that OP is interested in movement alone actually simplifies things (considerably)

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Show if cell is greater or smaller than previous value

    I believe we have a crosspost here:
    http://www.mrexcel.com/forum/showthread.php?t=429368

    ==============
    So the original macro adjusted like so:
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-13-2009
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Show if cell is greater or smaller than previous value

    Hi,

    The markets are now open and I am getting a DDE live feed.

    The original code supplied by Beau worked with well with manually entered data but, as I found out this morning, not with DDE data.

    The revised code from Don does work with the DDE real-time data.

    Thank you both very much for your help and interest.

    Chris

    Changing the subject:

    I have received a warning from this Excel Help Forum.
    Reason: Cross-posting.

    I have not posted this problem or a similar worded question anywhere else, so what is this about, why do I get a warning, what am I doing wrong?

    Chris

  12. #12
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Show if cell is greater or smaller than previous value

    Re: cross post - it would appear as though there has been a misunderstanding - Warning will be reversed.

  13. #13
    Registered User
    Join Date
    11-13-2009
    Location
    France
    MS-Off Ver
    Excel 2007
    Posts
    32

    Re: Show if cell is greater or smaller than previous value

    Don,

    Thank you for cancelling this warning and for you help with the code.

    Chris

    PS. I have looked at the cross post referred to in a earlier post. I agree it looks like the same problem as I have had, but the posting was definitely not done by me, or on my instigation.

+ 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