# VBA RND Function

Home ➜ VBA Functions LIST (Category Wise) ➜ **How to use the VBA RND Function (Syntax + Example)**

## What is VBA RND Function

The VBA RND function is listed under the math category of VBA functions. When you use it in a VBA code, **it generates a random number** that is greater than or equals to zero and lower than or equal to 1. In simple words, it returns a random number between 0 to 1. It works like the RAND function in the worksheet.

## how to use it

To use VBA's RND function you need to understand its syntax and arguments:

### Syntax

**Rnd([Number])**

### Arguments

**[Number]**: An optional numeric argument where you can specify [This is an optional argument and if omitted VBA takes >0 by default]:- <0 to get the same random number on each call, using [Number] as the seed number.
- =0 to get the most recently generated random number.
- >0 to get the next random number in the sequence.

## Example to use RND Function in VBA

To practically understand how to use VBA RND function, you need to go through the below example where we have written a vba code by using it:

Sub example_RND() Range("A1").Value = Rnd() Range("A2").Value = Rnd() Range("A3").Value = Rnd() End Sub

In the above code, we have used RND to get random numbers in the A1, A2, and A3. And if we re-run this it will return the different numbers in all three cells.

About the Author

Puneet is using Excel since his college days. He helped thousands of people to understand the power of the spreadsheets and learn Microsoft Excel. You can ﬁnd him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.