
Tips.Net > ExcelTips Home > Macros > Creating a Plus/Minus Button
Summary: The plus/minus button on a calculator provides a quick way to change a value from a positive to a negative value, and back again. There is no such button in Excel, but you can create one easily by applying the macro in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
On some calculators there is a little button that can come in very handy: the plus/minus button. This button, when pressed, will switch whatever value is on the display between its positive and negative values. For instance, if the display shows the number 57, then pressing the button will change the display to -57. Pressing it again will switch the value back to 57.
If you would like a "button" that does this in Excel, you'll quickly find that there is none built into the program. You can quickly create one, however, by using a macro:
Sub PlusMinus()
Dim cell As Range
For Each cell In Selection
If Application.IsNumber(cell) Then
cell.Value = cell.Value * -1
End If
Next cell
End Sub
Note that the macro simply steps through whatever range of cells you selected when the macro started. Each cell is checked to see if it contains a number. If it does, then the value of that number is multiplied by -1. The result is a switch in sign for the number.
You can assign this macro to a shortcut key or to a toolbar button to make it easy to use at any time.
Tip #3256 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
More Power! Expand your skills and make Excel really sing! It's all possible with macros. The best resource anywhere for macros is ExcelTips: The Macros. Check it out today!
PivotTables don't need to be scary or mysterious. Use this powerful tool to analyze your data in ways you didn't know were possible. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site