
Tips.Net > WordTips Home > Macros > Determining a Random Value
Summary: If you need to determine a random value in a macro, you can do so using the Rnd function. This tip presents the syntax and usage of the function. (This tip works with Microsoft Word 97, Word 2000, Word 2002, Word 2003, and Word 2007.)
VBA provides a function to return a random value in a macro. While the value of such a function in a word processor is debatable, the function nonetheless exists. The syntax for the function is as follows:
x = Rnd()
where x is the result. The value returned will always be between 0 and 1. To translate this to some other random value, all you need to do is multiply the result by the highest number you want to consider. For instance, if you wanted a random number between 1 and 25, you could use the following code line
x = Int(25 * Rnd()) + 1
Tip #1409 applies to Microsoft Word versions: 97 2000 2002 2003 2007
Take Control! Experienced users know that styles can make the difference between a plain document and a masterful one. This is the real power behind Word, and the key to that power can be found in WordTips: Styles and Templates.
Uncover how you can master the full potential of printing your documents. Everything you wanted to know about printing and printers, using Word. (more information...)
Ask a Word Question
Make a Comment
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips