Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Understanding Precedence.

Understanding Precedence

Written by Allen Wyatt (last updated March 6, 2021)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


Macros often contain mathematical formulas. Those formulas can sometimes become quite complex. Any time a formula contains more than one operator (such as + or -), VBA needs to figure out in which order to perform the operations. This is where the concept of precedence comes into play. Precedence is the built-in macro logic that determines the order in which the operations occur. This is the normal order:

Operator Meaning
^ Exponentiation
- Negation
* and / Multiplication and division
\ Integer division
Mod Modulus
+ and - Addition and subtraction

Notice that there are two entries in the precedence list in which there are two operators. Multiplication and division are at the same precedence level, as are addition and subtraction. If a formula involves two or more operators at the same precedence level, then the operators are evaluated from left to right within the formula.

If you want to change the order in which a formula is evaluated, you need to use parentheses. Operations within parentheses are evaluated before those outside of them. Thus, a formula such as 3 * (4 + 2) would produce a result of 18 because the addition within the parentheses takes precedence over the multiplication outside the parentheses. If the parentheses had been omitted, then 3 * 4 + 2 would have resulted in 14.

Note:

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

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12960) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Understanding Precedence.

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

Smart Quotes with Dragon Naturally Speaking

Dragon Naturally Speaking is a very popular transcription tool that converts speech into text. When using the program ...

Discover More

Adding Sidebars

When designing your document, you may want to use sidebars like you see in magazines and some books. This tip explains ...

Discover More

Formatting Canadian Postal Codes

Postal codes in Canada consist of six characters, separated into two groups. This tip explains the format and then shows ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Inserting a Paragraph from within a Macro

Macros are often used to process documents, resulting in changes of one manner or another. If you need your macro to add ...

Discover More

Highlighting Every Other Line

Macros are very good at completing mundane, repetitive tasks. For instance, you could use the macro presented in this tip ...

Discover More

Using Call to Run VBA Macros

An elegant way to run macros from within macros is to use the Call statement. In order to use it, you need to provide a ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.