Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50085

[SOLVED] Continuously Generate Random Numbers Until Minimum Reached entirely with VBA

$
0
0
Hey all,

I'm try to make my userform generate 6 random number that all meet a minimum value. I'd like to do this without cell references, so entirely within the VBA code. I've tinkered around and can't seem to make it work. Some tries did nothing, some ignored the minimum. Here's an example of the code I'm using.

Code:

Do While TextBox1.Value < MinimumNumberTextBox.Value
        Randomize
        MyNumber = Int((20 - 1 + 1) * Rnd + 1)
        TextBox1.Value = MyNumber
       
       
    Loop

I'm afraid there's circular logic stuff that might be preventing it from working, but not sure how to remedy. There will be six text boxes in total, so unless there's a way to make it look at each one in turn, I'll just end up running this six times in a row referencing different textboxes. If anyone can shed some light I'd be very greatful.

Viewing all articles
Browse latest Browse all 50085

Trending Articles