+ Reply to Thread
Results 1 to 5 of 5

To calculate 2 Live variables constantly changing !

  1. #1
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    To calculate 2 Live variables constantly changing !

    C1 AND D1 ARE LIVE VALUES WHICH ARE ALWAYS CHANGING. CI WILL ALWAYS BE EITHER THE SAME OR >OLDAVLUE C1. D1 CAN BE MORE OR LESS THAN THE PRVIOUS VALUE. I NEED TO CALCULATE 5 SUCH VALUES
    THIS MEANS THA I AM EXPECTING THE VALUES IN E1-E5( C2 TO D5 WILL BE LIVE VALUES. C2 IS NOW JUST TO TEST THE CODE
    please give the code for at least 2 lines

    e1=IF(C1>OldValueC1,(IF(D1=OldValueD1,IF(OldValueE1<0,OldValueC1-C1,C1-OldValueC1),IF(D1<OldValueD1,OldValueD1-C1,C1-OldValueD1))))
    Attached Files Attached Files
    Last edited by omega0010; 06-28-2013 at 03:01 PM.

  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: To calculate 2 Live variables constantly changing !

    1) Right-click the Sheet1 tab and select VIEW CODE

    2) Paste in this code to automatically operate within this sheet:

    Please Login or Register  to view this content.
    3) Close the vbeditor and see how it operates.

    You should be able to expand on this concept. The trick is we have declared some public variables at the top and store the current values of those cells each time we change the selected cell or change a value that causes a calculation to occur on the sheet.
    _________________
    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 Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    Re: To calculate 2 Live variables constantly changing !

    Thanks a lot to take the pain to write this code .
    Will try to see how it works
    Thanks again

  4. #4
    Forum Contributor
    Join Date
    12-11-2012
    Location
    India
    MS-Off Ver
    Excel 2019
    Posts
    308

    Re: To calculate 2 Live variables constantly changing !

    There is a slight change in the last two arguements but despite that the calculation is not coming through
    "ElseIf [D1] < vD1 Then
    [E1].Value = vC1- [C1]
    Else
    [E1].Value = [C1] - vC1"

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

    Re: To calculate 2 Live variables constantly changing !

    The macro is updating [E1] based on the logic outlined. You should be seeing something happening in [E1]. I trust you will work with the actual logic to get the math you want with the current vs prior values.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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