Excel RANDBETWEEN Function

The Excel RANDBETWEEN function returns a random number between two specified numbers

Example: Excel RANDBETWEEN Function

Excel RANDBETWEEN Function

METHOD 1. Excel RANDBETWEEN Function using hardcoded values

EXCEL

=RANDBETWEEN(-10,10)
Result in cell D5 (7) - returns a random number between -10 and 10. In this formula the top and bottom numbers between which you want to return a random number have been directly entered into the formula.

METHOD 2. Excel RANDBETWEEN Function using references

EXCEL

=RANDBETWEEN(B5,C5)
Result in cell D5 (7) - returns a random number between the numbers captured in cell B5 and C5, which are -10 and 10, respectively. In this formula the top and bottom numbers between which you want to return a random number have been entered into the formula as cell references.

METHOD 3. Excel RANDBETWEEN function using the Excel built-in function library with hardcoded values

EXCEL

Formulas tab > Function Library group > Math & Trig > RANDBETWEEN > populate the input boxes

=RANDBETWEEN(-10,10)
Note: in this example we are calculating a random number between -10 and 10.
Built-in Excel RANDBETWEEN Function using hardocded values

METHOD 4. Excel RANDBETWEEN function using the Excel built-in function library with references

EXCEL

Formulas tab > Function Library group > Math & Trig > RANDBETWEEN > populate the input boxes

=RANDBETWEEN(B5,C5)
Note: in this example we are calculating a random number between the numbers in cell B5 and C5.
Built-in Excel RANDBETWEEN Function using links

METHOD 1. Excel RANDBETWEEN function using VBA with hardcoded values

VBA

Sub Excel_RANDBETWEEN_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("RANDBETWEEN")
BottomNo = -10
TopNo = -10

'apply the Excel RANDBETWEEN function
ws.Range("D5") = WorksheetFunction.RandBetween(BottomNo, TopNo)

End Sub

PREREQUISITES
Worksheet Name: Have a worksheet named RANDBETWEEN.
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Top and Bottom numbers: Select the top and bottom numbers between which you want to generate a random number by changing numbers -10 and 10 in the VBA code to any number that doesn't conflict with the formula.

METHOD 2. Excel RANDBETWEEN function using VBA with references

VBA

Sub Excel_RANDBETWEEN_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("RANDBETWEEN")
BottomNo = ws.Range("B5")
TopNo = ws.Range("C5")

'apply the Excel RANDBETWEEN function
ws.Range("D5") = WorksheetFunction.RandBetween(BottomNo, TopNo)

End Sub

PREREQUISITES
Worksheet Name: Have a worksheet named RANDBETWEEN.
Top and Bottom Numbers: Ensure that the top and bottom numbers between which you want to generate a random number are captured in cells ("C5") and ("B5"), respectively.
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Top and Bottom numbers: Select the top and bottom numbers between which you want to generate a random number by changing the cell references ("C5") and ("B5"), respectively, in the VBA code to any number that doesn't conflict with the formula. Alternatively, change the values in cells ("C5") and ("B5").

Usage of the Excel RANDBETWEEN function and formula syntax

EXPLANATION

DESCRIPTION
The Excel RANDBETWEEN function returns a random numeric value between two numbers.
SYNTAX
=RANDBETWEEN(bottom, top)
ARGUMENTS
bottom: (Required) A number that represents the smallest value that the function can return. This number must be an integer.
top: (Required) A number that represents the largest value that the function can return. This number must be an integer.
ADDITIONAL NOTES
Note 1: The RANDBETWEEN function generates a new random number every time a worksheet is calculated. This includes opening a workbook.
Note 2: The RANDBETWEEN function will return an error if the bottom argumet is higher than the top argument.
Note 3: The RANDBETWEEN function will return an error if any of the arguments are not numeric.