VBA RND Function

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

What is VBA RND Function

how to use it

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




  • [Number]: An optional numeric argument where you can specify [This is an optional argument and if omitted VBA takes >0 by default]:
    1. <0 to get the same random number on each call, using [Number] as the seed number.
    2. =0 to get the most recently generated random number.
    3. >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 one point one

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 find him online, tweeting about Excel, on a running track, or sometimes hiking up a mountain.