I need help with what is probably a fairly easy VBA script, but i am new to VBA so, for lack of better words, I am stuck.
What i need is a script that will add two boxes together to get a sum in a third box, but where it is tricky for me is that i need the third box to retain the summed value even when either of the first two box values are deleted.
For example, say i have box A1=10, B1=40, and C1= SUM of A1 & B1 (so C1=50). Easy enough, but where im lost is that i want to be able to delete the value of either A1 or B1 and then have C1 still = 50, so then i can input another value into either A1 or B1 to continue to add to C1.
I hope this I explained this halfway decent, and any help would be greatly appreciated!
Last edited by ivander8; 03-31-2009 at 02:36 PM.
See if this does what you want
Right click sheet tab > select view code > paste in the below
VBA NoobCode:Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Not Intersect(Target, Range("A1:B1")) Is Nothing Then With Target If IsNumeric(.Value) And Not IsEmpty(.Value) Then Range("C1").Value = Range("C1").Value + Range("A1").Value + Range("B1").Value End If End With End If End Sub
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
VBA Noob,
I think the following line in your code
should be changed toHTML Code:Range("C1").Value = Range("C1").Value + Range("A1").Value + Range("B1").Value
HTML Code:Range("C1").Value = Range("A1").Value + Range("B1").Value
modytrane
Thanks modytrane but I had assumed the OP want to add the C1 value instead of resetting to zero
VBA Noob
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
your code works fine with the change I suggested.
If you enter a value in A1 and B1, C1 shows A1+B1.
After that if you delete,A1 and/or B1 C1 retains the sum from previous run.
If you enter new values in A1 and/or B1, C1 re-calculates the sum.
At no point in this sequence, you would need to add C1 to itself.
modytrane.
thanks for your help guys, its exactly what i need!
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
_________________________________________
![]()
![]()
Credo Elvem ipsum etian vivere
_________________________________________
A message for cross posters
Please remember to wrap code.
Forum Rules
Please add to your signature if you found this link helpful. Excel links !!!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks