Excel RAND Function

The Excel RAND function returns a random number between 0 and 1

Example: Excel RAND Function

Excel RAND Function

METHOD 1. Excel RAND Function

EXCEL

=RAND()
Result in cell B5 (0.78909571) returns a random number between 0 and 1. The RAND function generates a random number every time a worksheet is calculated.

METHOD 2. Excel RAND function using the Excel built-in function library

EXCEL

Formulas tab > Function Library group > Math & Trig > RAND

=RAND() Built-in Excel RAND Function

METHOD 1. Excel RAND function using VBA

VBA

Sub Excel_RAND_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("RAND")

'apply the Excel RAND function
ws.Range("B5") = Rnd

End Sub

PREREQUISITES
Worksheet Name: Have a worksheet named RAND.
ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell references ("B5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.

METHOD 2. Excel RAND function using VBA with a For Loop

VBA

Sub Excel_RAND_Function()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("RAND")

'apply the Excel RAND function from row 5 to row 10 with a For Loop

For x = 5 To 10

ws.Range("B"&x) = Rnd

Next

End Sub

PREREQUISITES
Worksheet Name: Have a worksheet named RAND.
ADJUSTABLE PARAMETERS
Output Column Range: Select the output column range by changing the column references ("B") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Output Row Range: Select the output row range by changing the for and to x values in the VBA code, that don't conflict with the formula.

Usage of the Excel RAND function and formula syntax

EXPLANATION

DESCRIPTION
The Excel RAND function returns a random number between 0 and 1.
SYNTAX
=RAND()
ADDITIONAL NOTES
Note 1: The RAND function generates a new random number every time a worksheet is calculated. This includes opening a workbook.