+ Reply to Thread
Results 1 to 22 of 22

Why does the value in E2 change without C2 being changed in this simle code ?

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

    How to put this Excel formula into a VBA code ?

    e1=IF(C1>OldValueC1,(IF(D1=OldValueD1, IF(OldValueE1<0,OldValueC1-C1, C1-OldValueC1),IF(D1<OldValueD1, OldValueD1-C1, C1-OldValueD1))))

    ( i.e. the result will come in the cell e1)
    I am really sick of trying since know more or less nothing about writing a code !
    Pleas help me as I am in urgent need to know this.
    Thanx !

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: How to put this Excel formula into a VBA code ?

    Hi omega0010, try
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How to put this Excel formula into a VBA code ?

    Hi Omega,

    you can use the vba code as range("e1").formula = "IF(C1>OldValueC1,(IF(D1=OldValueD1, IF(OldValueE1<0,OldValueC1-C1, C1-OldValueC1),IF(D1<OldValueD1, OldValueD1-C1, C1-OldValueD1))))"

    Not sure if your formula will work but above is a approach to put formula in vba


    Regards,
    DILIPandey
    <click on below * if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), dilipandey@gmail.com

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

    Re: How to put this Excel formula into a VBA code ?

    Thanx for the help but it doesnt work !

  5. #5
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How to put this Excel formula into a VBA code ?

    Okay... upload the workbook having this code.. thanks.



    Regards,
    DILIPandey
    <click on below * if this helps>

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

    Re: How to put this Excel formula into a VBA code ?

    Dear Dilip
    Please find the worksheet attached herewith
    Attached Files Attached Files

  7. #7
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: How to put this Excel formula into a VBA code ?

    Okay.. so values would be overwritten in c1 /d1

    Instead of your if formula, can you give your logic statement ?


    Regards,
    DILIPandey
    <click on below * if this helps>

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

    Re: How to put this Excel formula into a VBA code ?

    I think the formula should be
    [e1]=OldValueE1+(IF(C1>OldValueC1,(IF(D1=OldValueD1, IF(OldValueE1<0,OldValueC1-C1, C1-OldValueC1),IF(D1<OldValueD1, OldValueD1-C1, C1-OldValueD1)))))

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

    Can the designated row cells be copied and pasted to the last empty row.......

    If one of the cell value changes
    Suppose the rows are A, and B
    cells are A1 : C2


    These values in A1 : C2 are going to be live variable values.

    * I will prefer if a button can be assigned to copy data from A1:C2 and paste it in the last available row every time we press that button
    Last edited by omega0010; 07-13-2013 at 05:00 AM.

  10. #10
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Why does the value in E2 change without C2 being changed in this simle code ?

    Why does the value in E2 change without C2 being changed
    [E2] is never dependent with [C2]. E2 is dependent, on E2 itself & D2
    Please Login or Register  to view this content.
    OLDVALUE was never SETed..
    OLDVALUE was always JunkData or Nothing at the starting point.
    SET OLDVALUE = [C2] was never used


    I want that the value of anything should only change if C2 changes(
    Anything is not C2, is all cells..

    and when your are checking in this step..

    Please Login or Register  to view this content.
    E2 was never used..

    Finally..

    As you can see..
    Neither you able to grasp what i want to say..nor me able to understand what dyou want to achive..
    better.. dont provide code or request to check or correct your code..
    provide brief description actually you want you wanr to achive.
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

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

    Re: How to put this Excel formula into a VBA code ?

    Sorry but it does not work !
    Thanx for trying anyway

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Can the designated row cells be copied and pasted to the last empty row.......

    Every two seconds? AND every time they change? You're going to have tons of replicate data.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

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

    Re: Why does the value in E2 change without C2 being changed in this simle code ?

    I may not be able to understand all of it but I do understand the significance of Setting up all values. However since I am not aware of how this thing will get resolved. It may be days or even months before I can get my solution.
    It will be highly appreciated if you can just correct the code, because I may not be able to do so eventually !

    Brief description :
    1. The values in B2 and C2 will be constantly changing variable which will be live ( and there will be nothing in A3,B3 and C3)
    2. The idea is to calculate the changes in C2 and to show them in D2 ( C2 will always be > OldValueC2)
    3. B2 will be either <>0, but never 0
    4. The value in D2 will then be put in E2 if B2>0, else if B2<0 it will be put F2
    5. The occassion will similarly be counted and put in N2 and P2

    Thank you for being patient !
    Last edited by omega0010; 07-13-2013 at 04:27 AM.

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

    Re: Can the designated row cells be copied and pasted to the last empty row.......

    I have changed my request accordingly
    For this reason I will prefer if a button can be assigned to copy data from A1:C2 and paste it in the last available cell every time we press that butto(
    I have increased the range to 2 rows of copy n paste )

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

    Please rectify the top shelf of this code so that it becomes workable .....

    Please Login or Register  to view this content.


    The Logical area is exactly what I want and most probably accurate , but the code does not work...may be the address needs to be changed. Please see the attached file.
    Please make an effort to rectify this
    Attached Files Attached Files
    Last edited by omega0010; 07-13-2013 at 11:42 AM.

  16. #16
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Please rectify the top shelf of this code so that it becomes workable .....

    attach please a sample file with comments abaout your goal
    If solved remember to mark Thread as solved

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

    Re: Please rectify the top shelf of this code so that it becomes workable .....

    Please find the file attached

  18. #18
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Please rectify the top shelf of this code so that it becomes workable .....

    no idea what you are doing but right at the top of code you have
    Please Login or Register  to view this content.
    where did you define what oldvalue3 and oldvalue2 are
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  19. #19
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Please rectify the top shelf of this code so that it becomes workable .....

    Please Login or Register  to view this content.

  20. #20
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Can the designated row cells be copied and pasted to the last empty row.......

    The last row of the same sheet?

  21. #21
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Can the designated row cells be copied and pasted to the last empty row.......

    If you would like it pasted to the last row in the same sheet try this:

    Please Login or Register  to view this content.
    Create a button and assign this to it.

  22. #22
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Why does the value in E2 change without C2 being changed in this simle code ?

    Omega,

    I have merged all your duplicate threads. Please refrain from creating multiple threads for the same question. If repeated, you are likely to be banned.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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