I thought it would be simple

stevehard

New Member
Joined
Jun 3, 2008
Messages
3
I want to have a cell continually add the numerical values entered into another cell, so 55+40 entered into A2 would equal 95 in b2. I want to do this for the whole of column A but have the corresponding B column add eg. A5 is added in B5, A500 is added in B500. The following code adds the numbers entered in column A into cell B2, what do i change, obviously the B2 remark but to what?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If Target.Row > 1 And Target.Column = 1 Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("B2").Value = Range("B2").Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub

Many Thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to the board...
Use the Target.Row Property to determine the Row in Column B...

Try changing
Range("B2").Value = Range("B2").Value + .Value

to

Range("B" & .Row).Value = Range("B" & .Row).Value + .Value

Hope this helps.
 
Upvote 0
Also, this should make it a little more robust, as it is, it will error if more than 1 cell is changed at one time...

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Set MyRange = Intersect(Target, Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row))
If Not MyRange Is Nothing Then
    Application.EnableEvents = False
    For Each C In MyRange
        If IsNumeric(C.Value) Then
            Range("B" & C.Row).Value = Range("B" & C.Row).Value + C.Value
        End If
    Next C
End If
Application.EnableEvents = True
End Sub
 
Upvote 0
Absolutely fantastic, only had time to try the first one shall try after work but I can't thank you enough.
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,179
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top