The other day I needed to write a bit of VBA code that involved the random selection of an integer between two numbers. Let's say you want to generate a random integer between 500 and 800. Here's how to make that happen with VBA, storing it in a variable I'm calling randomNumber:
Dim randomNumber As Integer
Randomize
randomNumber = Int((800-500+1) * Rnd + 500)
Read More
Dim randomNumber As Integer
Randomize
randomNumber = Int((800-500+1) * Rnd + 500)