This Excel tutorial explains how to use the Excel RND function with syntax and examples.
lowerbound is the lowest value that the random number can be.
Let's look at some Excel RND function examples and explore how to use the RND function in Excel VBA code:
Description
The Microsoft Excel RND function allows you to generate a random number (integer value). You can specify the random number to be a value between 2 user-specified numbers.Syntax
The syntax for the Microsoft Excel RND function is:Int ((upperbound - lowerbound + 1) * Rnd + lowerbound)
Parameters or Arguments
upperbound is the highest value that the random number can be.lowerbound is the lowest value that the random number can be.
Applies To
The RND function can be used in the following versions of Microsoft Excel:- Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000
Type of Excel Function
The RND function can be used in Microsoft Excel as the following type of function:- VBA function (VBA)
Example (as VBA Function)
The RND function can only be used in VBA code in Microsoft Excel.Let's look at some Excel RND function examples and explore how to use the RND function in Excel VBA code:
Int ((6 - 1 + 1) * Rnd + 1) Result: random number between 1 and 6 Int ((200 - 150 + 1) * Rnd + 150) Result: random number between 150 and 200 Int ((999 - 100 + 1) * Rnd + 100) Result: random number between 100 and 999For example:
Dim LRandomNumber As Integer LRandomNumber = Int ((300 - 200 + 1) * Rnd + 200)