Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Creating a Plus/Minus Button.
by Allen Wyatt
(last updated March 22, 2018)
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 If Not(IsDate(cell)) Then cell.Value = cell.Value * -1 End If 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 cell is checked to make sure it doesn't contain a date. Only then is the value of the cell multiplied by -1. The result is a switch in sign for the number.
The two checks done on the cell are important so that you don't mess up the contents of cells by accident. The first check (using the IsNumber function) looks to see if the cell contains a number. When would a cell not contain a number? The most critical time is when it contains a formula; you don't want to mess those up. The second check uses the IsDate function, which checks to see if the cell contains a date. This is necessary because a cell can contain a number that actually represents a date, and you don't want to change those dates to minus values.
You can assign this macro to a shortcut key or add it to the Quick Access Toolbar to make it easy to use at any time.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9271) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Creating a Plus/Minus Button.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Got a workbook cluttered with all sorts of macros? Delete them and you'll make your workbook easier to manage.Discover More
Got a workbook that has lots and lots of macros associated with it? Here's a way you can get a list of all of those ...Discover More
When you open multiple workbooks, the way in which Excel sizes them is not the best for your needs. This tip looks at a ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.