Auto add to a cell when new value is entered in another cell

  • Hello there,


    I'm trying to know the expenses by doing the following :


    I have two simple cells, A1 and B1
    What I want to do is every time I add a number in A1, I want it to be automatically added to B1, then reset A1 to zero
    The next day I will add a number in A1, and it will be automatically added to the number in B1, then reset A1 to zero again ... And so on.


    Any suggestions?

  • I got the code in VB.


    May I ask another question, how to do it on different cells in the same sheet ?
    Let's say I want it to be A1, B1 and then A2, B2
    Do I have to copy the code and paste it again in VB and change the cell numbers ? Or just modify the existing code and add the required cell numbers ?

  • Hello,


    In order to correctly modify the macro ...


    Could you kindly expose our final objective ...

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

  • Hello,


    In order to correctly modify the macro ...


    Could you kindly expose our final objective ...


    Sure, you can refer to attached image below.


    Here is what I want do to ..
    I want to have the same code, you have provided, to work for each two cells.
    I have colored the cells for you.


    I will add numbers every time in the red cells.
    The blue cells will show me the total expenses from red cells.


    [ATTACH=JSON]{"data-align":"none","data-size":"full","data-attachmentid":1196907}[/ATTACH]


    https://i.imgur.com/lfstofA.png

  • Hello,


    You can test following code:


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Intersect(Target, Range("C17,E17,G17,I17,K17,M17,O17,Q17,S17,U17,W17,Y17")) Is Nothing Then Exit Sub
    If Target = "" Or Not IsNumeric(Target) Then Exit Sub
    Application.EnableEvents = False
    Target.Offset(0, 1) = Target.Offset(0, 1) + Target
    Target.ClearContents
    Target.Select
    Application.EnableEvents = True
    End Sub


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

  • That was PERFECT.


    Thank you so much sir, I appreciate your time and effort.


    Best Regards,


    Glad you could fix your problem ...:wink:


    Thanks a lot ... for your Thanks ...AND for the Like ... :smile:

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!