Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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.

Creating a Plus/Minus Button

Written by Allen Wyatt (last updated November 23, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


2

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

    On Error Resume Next 'copes with cells that are not numeric
        For Each cell In Selection
            If Not cell.HasFormula Then cell.Value = -cell.Value
    Next cell
End Sub

Note that the macro simply steps through whatever range of cells you selected when the macro started. Each cell is tested to make sure it contains a numeric value. 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. Another instance is when the cell contains a date. You don't want to change those dates to minus values. Cells that contain either a formula, a date, or a label will generate an error since "cell.Value" isn't a numeric value. If the cell truly contains a number, then the result is a switch in sign for the number.

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.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9271) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Creating a Plus/Minus Button.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Quickly Displaying the Font Dialog Box

Want to quickly format some text in your document? Select, right-click, and make a selection, and you can get to the ...

Discover More

Setting Row Height in a Macro

Macros can be used to change the formatting of your worksheet, if desired. One change you might want to make is to the ...

Discover More

Using Duplex Printing

Need to print on both sides of a piece of paper? If your printer can handle it, you can duplex your output from within ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Removing a Directory

Macros allow you to perform all sorts of file-related operations. One such operation allows you to delete a directory. ...

Discover More

Item Not Available in Library

When sharing workbooks with others, you may find that the macros in those workbooks may not work as you expect. This tip ...

Discover More

Copying Worksheets in a Macro

Copying worksheets (one or many) is easy to do manually. What is not well known is that it is even easy to make the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 5?

2021-12-05 10:25:50

J. Woolley

The subject of this Tip is very similar to a recent Tip titled Negating a Cell Using a Macro. That Tip attracted a plethora of Comments.
See https://excelribbon.tips.net/T010127_Negating_a_Cell_Using_a_Macro.html

My Excel Toolbox includes the Negate macro to negate all numeric constants in a Selection (ignoring other cells). The Negate macro supports Undo.
See https://sites.google.com/view/MyExcelToolbox/


2021-12-04 19:48:37

Fernando Ramos

Hi Allen.
Great code.
A small observation: If you apply this code to empty cells it will change it to a cell with a zero.
This small change should fix that.

Sub PlusMinus()
Dim cell As Range

On Error Resume Next 'copes with cells that are not numeric
For Each cell In Selection
If Not cell.HasFormula and cell.Value <> 0 Then cell.Value = -cell.Value
Next cell
End Sub

Greetings from Mexico


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.