MrExcel Publishing
Your One Stop for Excel Tips & Solutions

add or subtract popup box


Posted by Tom on September 06, 2001 11:16 AM

We have excel files that have a lot of numbers in them. Is there a way when you are on a cell to activate a macro to pop up a box so you can add or subtract from the number in the cell.


Posted by Ben O. on September 06, 2001 2:30 PM

Here are two simple macros to do what you want. If you want the same macro to add/subtract depending on what the user chooses, you'll have to add some coding or (preferably) create a userform.

Sub AddtoCell()
oNumb = ActiveCell.Value
uNumb = InputBox("Enter Number to Add", "Add Number")
nNumb = oNumb + uNumb
ActiveCell.Value = nNumb
End Sub


Sub SubtractfromCell()
oNumb = ActiveCell.Value
uNumb = InputBox("Enter Number to Subtract", "Subtract Number")
nNumb = oNumb - uNumb
ActiveCell.Value = nNumb
End Sub


Assign these macros to hotkeys or to toolbar buttons for quick access.

-Ben