Written by Allen Wyatt (last updated July 2, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
Excel provides a power function that allows you to easily return a random integer number within a range. For instance, you can use the RANDBETWEEN function to return a random integer number between 50 and 99, or between -25 and 0. The syntax for the function is as follows:
=RANDBETWEEN(lower, upper)
All you need to do is provide the lower and upper values. If the first number you provide is actually higher than the second number, then RANDBETWEEN returns a #NUM! error.
Remember that RANDBETWEEN works only with whole numbers—integers. If you need, instead, to get non-integer values, then you need to use RANDBETWEEN in a bit more complex of a formula. For instance, if you want to have values between 1 and 2, then you could use a formula such as this:
=RANDBETWEEN(100, 200) / 100
This will provide values two two decimal places. If, instead, you wanted values to three decimal places, just make 1000 and 2000 your bounds and divide by 1000.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12364) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Random Numbers in a Range.
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!
Need to know the character value of the first character in a string? It's easy to do, without using a macro, by using the ...
Discover MoreExcel includes a handy function that allows you to repeat characters or strings of characters. How you use the REPT ...
Discover MoreThe SUMIF function is supposed to work just fine doing comparisons with text values. This isn't a hard-and-fast rule, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-07-02 05:20:44
Andy
The newer RANDARRAY function available in Excel 365 is worth looking at as well. https://support.microsoft.com/en-us/office/randarray-function-21261e55-3bec-4885-86a6-8b0a47fd4d33
As well as the option of random integers within a range, it also allows decimal values and can return an array of random values.
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 © 2025 Sharon Parq Associates, Inc.
Comments