+ Reply to Thread
Results 1 to 9 of 9

revert cell value if the sum does not satisfy a condition

  1. #1
    Registered User
    Join Date
    02-10-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    revert cell value if the sum does not satisfy a condition

    Hi All,

    I am completely new to macros and programming.
    I request your kind help for a small task
    I have cell A1, cell B1 . The value of cell C1=(A1+B1)
    The value of C1 should be equal to 100 only.
    If the user changes value of A1 or B1 which makes the value of C1 not equal to 100 ,then there could be a pop up saying this value should be 100 only and then the valuse of A1 and B1 should be reverted back to the original values.

    Kindly help in this
    Thanks in advance to all

    Regards

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

    Re: revert cell value if the sum does not satisfy a condition

    I don't really see how that works logically.

    If A1 is 20 and B1 is 80 how do you change either cell without the sum becoming something other than 100 at least temporarily ?

    You can't enter two different values to A1:B1 simultaneously unless you copy and paste from elsewhere.

  3. #3
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: revert cell value if the sum does not satisfy a condition

    Yes. If you can accept a null in one of the cells, perhaps a data validation can help.
    Attached Files Attached Files
    regards

    johnjohns

    When you are not sure where to go, every road takes you there!

  4. #4
    Registered User
    Join Date
    02-10-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: revert cell value if the sum does not satisfy a condition

    Hi ,

    Sorry for not being very clear about this

    The values in A1 and B1 will be manually entered .The data in prev years sheet has to be refreshed
    e.g.
    A B C
    60 40 =(A1+B1)
    If now while refreshing his data if the user enters A1 = 70, B1 = 40 then the value of C1 would be 110
    Now he should get a msg saying total can be 100 only. and the valuse of A1 should revert back to 60, so that the user knows what was his last years value.

    Please let me know if it can be done...

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

    Re: revert cell value if the sum does not satisfy a condition

    Quote Originally Posted by spawn0310
    60 40 =(A1+B1)

    If now while refreshing his data if the user enters A1 = 70, B1 = 40 then the value of C1 would be 110

    Now he should get a msg saying total can be 100 only. and the valuse of A1 should revert back to 60, so that the user knows what was his last years value.
    I reiterate; logically - this makes no sense given the simple fact that if C1 is 100 you can not alter A1 & B1 ... C1 would become <> 100 and you would revert back - ergo A1 & B1 remain constant.

  6. #6
    Registered User
    Join Date
    02-10-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: revert cell value if the sum does not satisfy a condition

    Thankyou very much for the help John.
    Aprpeciate the help DonkeyOte...
    Yes the cell value of A1 and B1 will remain the same if the cell value is not equal to 100
    however any other changes in the value of A1 and B1 which will maintian the condition will be accepted.

    JohnJohns : Can you enable this for the entire column A, B and C.
    Also could you please tell me how you did it....can you share the macro code please.

    Thanks
    Last edited by spawn3010; 02-10-2011 at 06:26 AM.

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

    Re: revert cell value if the sum does not satisfy a condition

    @spawn3010, my understanding from your posts thus far:

    A1: 30

    B1: 70

    A1 & B1 are to be changed manually

    A1 & B1 aggregated must remain = 100

    If A1 & B1 aggregated <> 100 changes must be reversed


    If the above is correct:

    The only ways A1 & B1 can be altered manually in Excel whist satisfying the above conditions are:

    a) Highlighting A1 & B1, typing 50 and whilst holding CTRL pressing Enter.

    or

    b) Highlighting A1 & B1, typing in say ={2,98} and whilst holding SHIFT + CTRL pressing Enter (ie entering an Array formula)

    Any singular alteration to the constants in A1 / B1 would result in a balance other than 100.
    Per your logic they would be immediately reversed.

  8. #8
    Forum Contributor johnjohns's Avatar
    Join Date
    11-19-2007
    Location
    Dubai, UAE
    MS-Off Ver
    2003 and 2007
    Posts
    526

    Re: revert cell value if the sum does not satisfy a condition

    You can copy A1 and B1 and paste to the below cells. I used no macros, but data validation. See the data validation.

  9. #9
    Registered User
    Join Date
    02-10-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: revert cell value if the sum does not satisfy a condition

    I now got your point DonkeyOte.
    I will get more details from the user who actually is going to use the file..
    Thanks for informing..I actually did not think on that path....

    Thanks JohnJohns.... I learnt a bit more of data validation from you ...

    The thread can be closed Sir. Thanks for all the help provided..

+ 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