VBA Function – Populating a Range With Random Values

Associated Files Download Links

Populate Cells With Random Values

The following code will populate a given range with a random number between 0 and 1000:

The code “Application.ScreenUpdating =FALSE” and “Application.ScreenUpdating = TRUE” serve to turn off and turn on screen alerts – making the code much faster to run.

It can be set up via a click event, with the main routine specifying the range:

So this case, cells A1:T8000 on sheet 3 are populated with random numbers – once the command button 1 is clicked.

Download the .XLSM file here

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!

<<Return to VBA Examples

Did you find this VBA tutorial useful? Then share it with your friends and colleagues:

You may also like some of this related content...

We have already gone over what variables and constants are, in our VBA Data Types
Union - Join Multiple Ranges You might want to combine or join multiple ranges if
Delete all Named Ranges From a Workbook To delete all Named Ranges in a Workbook,
Conditional Formatting - Highlight Duplicates To highlight all duplicate values in a range you will
Here is example code to determine the Start and End Column of a Merged Cell.