-1

I have this code to add value of a cell to an existing value of the other cell:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    If Not (Intersect(Target, Range("E3")) Is Nothing) Then
        Range("F3").Value = Range("E3").Value + Range("F3").Value
    End If
End Sub

But my problem is it just work in one cell, but not in a row, that is e. g. I want to add up B1 value to A1 existing value. It works OK, but i have 24 rows, that is B2 to A2 it don't work I don't want to add them combine but separably B2 to A2 and B3 to A3 this way 24 times.

Please help, it's urgent.

1
  • What? All this does is add E3 to F3 if your changed E3? I don't understand your question. Feb 12, 2014 at 18:34

1 Answer 1

0

Does it have to be vba?

If you select column B copy (ctrl+c) then select column A and goto paste special you can use the add operator to do what you want.

Otherwise this function would work everytime you change a cell in column B it would update column A as column A+column B (for the specific row).

Gordon

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim int_range As Range

Set int_range = Intersect(Target, Range("B:B"))
If Not (int_range Is Nothing) Then
    For Each c In int_range
        c.Offset(0, -1).Value = c.Offset(0, -1).Value + c.Value
    Next
End If
End Sub

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .