I have a sheet in Excel with a list of numbers. Sometimes I want to move X units from one cell to another.
Let's say I have a classroom of kids, each one has a certain number of marbles. There are 2 columns in the sheet, first column is names, second column is marbles. John gives 375 marbles to Bill. I want to update the sheet.
Currently I pull out a calculator, do the subtraction and addition, and update the cells manually.
This is cumbersome and error-prone. Is there a better way?
(I know I can write "=8300+375" in the cell but eventually each cell will have a stupidly long formula..)
32 Answers
You can use paste special to easily perform the calculations.
- Enter
-375in one cell and375next to it. - select your new numbers and press CTRL+C
- Select the cells you want to change.
- in the ribbon / home / paste / "paste special"
- check "add" then "ok"
Máté Juhász post inspired me to suggest you VBA Macro, Since it's faster and time saver too. And I do believe that You can handle it.
How it works:
- I'm assuming that you have data in Range
A2:B4. Put Values you want to Subtract in
C2:C4.From Developer TAB, click Design Mode
then Insert & From ActiveX Controls
click Command Button Icon and draw it on
the Sheet.Click the Command Button, you reach to VB editor Windows.
Copy & Paste this code between
Private Sub CommandButton1_Click()
End Sub.
Range("C2:C4").Select Selection.Copy Range("B2").Select Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlSubtract, SkipBlanks:= _ False, Transpose:=False Range("C2:C4").Select Selection.ClearContents Application.CutCopyMode = FalseFrom VB editor Windows click File menu then hit Close & Return to Microsoft Excel.
Finally Click on Command Button.
You find New Values in Column B,(check Screen shot).
N.B.
If you want to Subtract Old vlaue from New Value in a Cell only, then you may use this VBA code.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 2 And Target.Row = 1 Then NewVal = Range("B1").Value Application.EnableEvents = False Application.Undo OldVal = Range("B1").Value Range("B1").Value = NewVal Range("B1").Value = NewVal - OldVal Application.EnableEvents = True
End If
End SubPress ALT+F11 to open VB editor and Copy & Paste the above shown code as Standard Module.
As soon you overwrite Value in
B1, code will
Subtract it from Old Value and re-writeB1
with New Value.
Adjust Data Range as your need.