Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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: Generating Double-Digit Random Numbers.
by Allen Wyatt
(last updated October 25, 2014)
Venkataramanan needs to generate random numbers in the range of -99 to +99, excluding single-digit numbers (-9 to +9). He wonders if there is a way to accomplish the task.
There are a couple of worksheet functions that are often used to generate random numbers in Excel. The RAND function is used to generate a random number between 0 and 1, while the RANDBETWEEN function is used to generate a random number within a range of numbers.
There is no function to do what Venkataramanan wants to do, but you can write a formula that will do the trick. Consider this formula:
The first RAND function determines if the result is '+' or '-' and the next RANDBETWEEN function returns the desired number between 10 and 99. When the function is done, you have the desired double-digit random number.
Another formula is similar in nature:
The first part generates whole numbers in the range of 0 through 89. The formula adds 10 to this, effectively giving a number from 10 to 99. The second part of the formula is then used to randomly determine whether the result should be positive or negative.
Another approach relies entirely on the RANDBETWEEN function and doesn't use any multiplication:
The formula puts together a string that consists of either a minus sign or a blank followed by two digits. The formula then uses the VALUE function to convert the string to a numeric value. An even shorter version of the formula would be this:
Another similar formula is the following:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10611) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Generating Double-Digit Random Numbers.
Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!
You can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in ...Discover More
Want to figure out how far it is between two points on the globe? If you know the points by latitude and longitude, you ...Discover More
When you need to pull information from a lot of different worksheets into a single worksheet, it can be baffling to ...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.