Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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.
Written by Allen Wyatt (last updated November 18, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
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:
=IF(RAND()>0.5,1,-1)*(RANDBETWEEN(10,99))
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:
=ROUND(RAND()*89+10,0)*((RAND()<0.5)*2-1)
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:
=VALUE(IF(RANDBETWEEN(0,1)=0,"-","")&RANDBETWEEN(1,9)&RANDBETWEEN(0,9))
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:
=VALUE(IF(RANDBETWEEN(0,1)=0,"-","")&RANDBETWEEN(10,99))
Another similar formula is the following:
=RANDBETWEEN(10,99)*IF(RANDBETWEEN(0,1),1,-1)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10611) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Generating Double-Digit Random Numbers.
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!
When compiling statistics on a collection of data points, you may want to know whether a particular value is the "highest ...
Discover MoreYou can easily set up a formula to perform some calculation on a range of cells. When you copy that formula, the copied ...
Discover MoreIf you have a series of values in a range of cells, you may wonder how many of those values are even and how many are ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments