Explanation
The RANDBETWEEN function takes two numbers, a bottom and top number, and generates a random integer in between. Dates in Excel are serial numbers, so you can use the DATE function to create the lower number and the upper number. RANDBETWEEN then generates a number that falls between these two date values.
Notes:
- The result of this formula must be formatted as a date to display correctly.
- The RANDBETWEEN function is volatile and will generate new numbers whenever a change occurs on the worksheet. That includes any edits to the worksheet, or simply opening the workbook.
- To prevent random numbers from being calculated again, copy the formulas, then use Paste Special > Values to replace the formulas with their calculated values.
Random workdays
To generate random workdays, you can add the WORKDAY function like this:
=WORKDAY(RANDBETWEEN(date1,date2)-1,1)
The WORKDAY function ensures that the date returned is a work day and not a weekend or holiday. Note that WORKDAY will shift dates that fall on weekends or holidays to the next working day, so you may see dates that extend beyond date2.
Explanation
The Excel RANDBETWEEN function returns a random integer between given numbers. In the example shown, the formula in B5 is:
=RANDBETWEEN(1,100)
This formula is then copied down from B5 to B11. The result is random numbers between 1-100.
RANDBETWEEN is a volatile function that recalculates when a worksheet is opened or changed. This includes any edits to the worksheet, or simply opening the workbook. To prevent random numbers from being recalculated again, you can replace the formulas with the values last calculated:
- Select the random numbers
- Copy the formulas to the clipboard with Control + C.
- Open the Paste Special Window and select “Values”
- Click OK to replace the formulas with static values.
Notes
- The RAND function can generate random decimal values.
- The RANDARRAY function (new in Excel 365 ) can generate random numeric arrays.