unique random number in VBA help

Dabaron2321

New Member
Joined
Jan 20, 2016
Messages
9
Hi i'm using the following macro that is set to run every time i press my form button:

Sub One()


Range("b1:B1000").Value = Int((200 - 1 + 1) * Rnd + 1)

End Sub

the problem is when i press the button each cell brings back the same result, ie. all the cells display 154 then when pressed again all show 86 then all show 5 etc, when i want all the cells between b1 and b1000 to function independent to each other, yet i don't want to have run a separate formula for each cell? Any advice?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG14Jul27
[COLOR="Navy"]Dim[/COLOR] R [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] R [COLOR="Navy"]In[/COLOR] Range("b1:B1000")
    R.Value = Int((200 - 1 + 1) * Rnd + 1)
[COLOR="Navy"]Next[/COLOR] R
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:

Sub fillRandomNumbers4A()Dim cell As Range
For Each cell In Range("C3:H14")
Dim Low As Double
Dim High As Double
Low = 11 '<<< CHANGE AS DESIRED
High = 20 '<<< CHANGE AS DESIRED
cell = Int((High - Low + 1) * Rnd() + Low)
Next cell
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top