Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Creating a Plus/Minus Button.
by Allen Wyatt
(last updated June 20, 2015)
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 PlusMinus1() 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.
One drawback to the macro is that if the cell contains a formula, that formula is converted to a value and then multiplied by the -1 value. You may not want to lose your formulas. In that case, you could rely on a more discriminating macro, one that checks to see if the cell contains a formula or not. If not, then it is simply multiplied by -1. If so, then the formula is adjusted so that the result is multiplied by -1.
Sub PlusMinus2() Dim cell As Range For Each cell In Selection If Left(cell.Formula, 1) = "=" Then Cell.Formula = cell.Formula & " * -1" Elseif Application.IsNumber(cell) Then cell.Value = cell.Value * -1 End If Next cell End Sub
You can assign either of these macros to a shortcut key or to a toolbar button to make it easy to use at any time.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3256) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Creating a Plus/Minus Button.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
Excel allows you to fill a cell's background with just about any color you want. If you need to determine the RGB value ...Discover More
Variable arrays are used quite often in macros. If you use an array once in your macro and then need to reuse it for ...Discover More
If you are using a macro to process a number of worksheets, you may have a need to know if the worksheet is empty or not. ...Discover More
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.