ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Adding or subtracting numbers from a column (https://www.excelbanter.com/excel-discussion-misc-queries/174642-adding-subtracting-numbers-column.html)

Richard[_4_]

Adding or subtracting numbers from a column
 
I would like to have a column of numbers and by typing in numbers in an
adjacent column add these numbers to the ones in the column. As the numbers
in the column change it would be nice if the ones I am typing in returned to
zero. If anyone knows haow to do this I will be impressed and grateful if
they tell me how.
Thank you
--
Richard

Otto Moehrbach

Adding or subtracting numbers from a column
 
Richard
One way:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Column = 2 And Target.Row 1 Then
If IsNumeric(Target.Value) And _
IsNumeric(Target.Offset(, -1).Value) Then
Target.Offset(, -1).Value = Target.Offset(, -1).Value +
Target.Value
Application.EnableEvents = False
Target.ClearContents
Application.EnableEvents = True
End If
End If
End Sub
This is a worksheet event macro and must be placed in the sheet module of
the sheet in which you want this to work. To access that module,
right-click on the sheet tab and select View Code. Paste this macro into
that module. "X" out of the module to return to your sheet.
As written, this macro reacts to a numeric entry in Column B and adds that
entry to Column A if the entry in Column A is also numeric or blank. Change
the column number as needed. HTH Otto
"Richard" wrote in message
...
I would like to have a column of numbers and by typing in numbers in an
adjacent column add these numbers to the ones in the column. As the
numbers
in the column change it would be nice if the ones I am typing in returned
to
zero. If anyone knows haow to do this I will be impressed and grateful if
they tell me how.
Thank you
--
Richard




Mike H

Adding or subtracting numbers from a column
 
Richard,

Try this. As you type numbers in B1 - B10 they are added to any number in A1
- A10. You can change these ranges to suit.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count 1 Or IsEmpty(Target) Then Exit Sub
If Not Intersect(Target, Range("B1:B10")) Is Nothing Then
If IsNumeric(Target.Value) Then
Target.Offset(0, -1).Value = Target.Offset(0, -1).Value +
Target.Value
Target.Value = 0
End If
End If
End Sub

Mike

"Richard" wrote:

I would like to have a column of numbers and by typing in numbers in an
adjacent column add these numbers to the ones in the column. As the numbers
in the column change it would be nice if the ones I am typing in returned to
zero. If anyone knows haow to do this I will be impressed and grateful if
they tell me how.
Thank you
--
Richard



All times are GMT +1. The time now is 12:50 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com