Excel RANDBETWEEN Function
The Excel RANDBETWEEN function returns a random number between two specified numbers
Example: Excel RANDBETWEEN Function
=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.
|
=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. |
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. |
Sub Excel_RANDBETWEEN_Function()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("RANDBETWEEN")
BottomNo = -10
TopNo = -10
TopNo = -10
'apply the Excel RANDBETWEEN function
ws.Range("D5") = WorksheetFunction.RandBetween(BottomNo, TopNo)
ws.Range("D5") = WorksheetFunction.RandBetween(BottomNo, TopNo)
End Sub
PREREQUISITES
Worksheet Name: Have a worksheet named RANDBETWEEN.
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.
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.
Sub Excel_RANDBETWEEN_Function()
'declare a variable
Dim ws As Worksheet
Dim ws As Worksheet
Set ws = Worksheets("RANDBETWEEN")
BottomNo = ws.Range("B5")
TopNo = ws.Range("C5")
TopNo = ws.Range("C5")
'apply the Excel RANDBETWEEN function
ws.Range("D5") = WorksheetFunction.RandBetween(BottomNo, TopNo)
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.
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").
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").
DESCRIPTION
The Excel RANDBETWEEN function returns a random numeric value between two numbers.
The Excel RANDBETWEEN function returns a random numeric value between two numbers.
SYNTAX
=RANDBETWEEN(bottom, top)
=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.
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.
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.