Return to VBA Code Examples

VBA Rnd Function

Rnd Function

Used to change the seed value used by the random number generator for the Rnd function.

Simple Rnd Examples

Rnd Syntax

In the VBA Editor, you can type  “Rnd(” to see the syntax for the Rnd Function:

The Rnd function contains an argument:

Number: [Optional] Any valid numeric expression.

Examples of Excel VBA Rnd Function

To generate random integer value between 1 and 10, you can use the following code.

This code will generate 20 random integer value between 1 and 10.

To generate random value between an lower bound and an upper bound, you can use the following function.

This will return a random value between 5 and 30.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!