Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. 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: Determining If a Number is Odd or Even.
by Allen Wyatt
(last updated May 10, 2014)
A common programming task is validating user input. Often, you may need to determine if a number entered by a user is odd or even. For instance, suppose you wrote your own macro that asked the user what page number of the document they wanted to process. If your macro had to process odd and even pages differently, then you need to figure out if the number the user provided was odd or even. The technique for this is relatively simple, as shown here:
Even = (UserNum Mod 2) - 1
After execution of this line, Even will be True (-1) if UserNum was even, or False (0) if UserNum was odd.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (8962) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Determining If a Number is Odd or Even.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
Macros are part of the document and template that are loaded into memory when you open a file. If you have "junk" macros in ...Discover More
Do you need to step through a table, cell by cell, in a macro? It's easy to do using the Move method, as described in this ...Discover More
When you distribute documents to other people, you may want those documents to have associated macros that the reader can ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.