#1
|
|||
|
|||
Filling cells with random numbers using loops? (VBA)
Hello,
I need to write a mcro that fills all the cells in the block range of cell with random numbers between 0 and 1. so far I've done this: Sub number() Dim x As Double For x = 1 To 10 Workbooks("book1").Sheets("Sheet1").Range("A1:f20" ).Offset(x, j).Value = Rnd() Next End Sub the problem with my macro is having one random number on almost the entire determined range. |
#2
|
||||
|
||||
Why do you need a macro, when the =RAND() worksheet function can achieve the same result - and change it every time to workbook updates?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I wanted to assign a macro to any shape in order to give set of different random numbers between 0&1 just to make it easier for any one else.For that, I'm sure that I have to use the For next loop.
|
#4
|
|||
|
|||
got it
Sub randoms() Dim randoms As Range Range("a1:f20").Select For Each randoms In Selection object.Value = Rnd() Next End Sub |
#5
|
||||
|
||||
There is no need to select anything. Also, in one place your code refers to 'randoms', but then uses a different name (object) to output the value. Such inconsistencies can lead to serious problems in a more complex macro. Try:
Code:
Sub Randoms() Dim Rng As Range For Each Rng In Range("A1:F20") Rng.Value = Rnd() Next End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to fill a cell with random numbers to do calculations? | zanat0s | Excel | 1 | 06-13-2011 10:33 AM |
filling multiple cells whislt using Filter | VinceO | Excel | 1 | 05-09-2011 06:38 AM |
Display Random Numbers as Transition | greenbutton | PowerPoint | 0 | 03-09-2011 04:43 PM |
Powerpoint loops, but not to beginning | imeister | PowerPoint | 1 | 02-02-2011 02:05 PM |
loops within presentations | supateach | PowerPoint | 1 | 11-23-2010 04:42 AM |