Generate Random Numbers with no duplicates

jmcmahon

New Member
Joined
Jan 21, 2003
Messages
10
I need to generate 5 random numbers
from 1 to 15 in cells a3 to a7 with
no duplicates.

I currently use the code =RANDBETWEEN(1,15)
in each cell which works great, but it can generate a duplicate number.

Is there code I can add to =RANDBETWEEN(1,15)
That would not create a duplicate number
in cells a3 to a7?
Or possible VB code to do the same?

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I have Excel 2000, I can't seem to get the
morefunc addin installed.

I've tried everything I can think of to get
it installed and my addins won't recognize it.
 
Upvote 0
On 2003-02-15 16:31, jmcmahon wrote:
I have Excel 2000, I can't seem to get the
morefunc addin installed.

I've tried everything I can think of to get
it installed and my addins won't recognize it.

Unzip morefunc.zip in a New Folder on your destop.
Open the folder C:Program FilesMicrosoft OfficeOfficeLibrary in Windows Explorer or via My Computer.
Drag and Drop the following files from New Folder into ...Library

MOREFUNC.CNT
Morefunc.GID
MOREFUNC.HLP
Morefunc.xll

Start Excel
Activate morefunc via Tools|Add-Ins.
 
Upvote 0
I've tried that again and it still doesn't work. When I type in {=MRAND(5,,15)}
in the formula bar it just gives me ###
or just show the formula in the cell.

At this point i'd settle for a vb solution
instead of an addin.

I click on tools then addins then I click
on the box for morefunc (add in functions)
Then I click on OK then I get nothing.

When the other add-ins are highlighted, there is a description at the bottom of the add-in, when morefunc is highlighted there is no description at the bottom.

Could that be a problem?
 
Upvote 0
On 2003-02-15 17:11, jmcmahon wrote:
I've tried that again and it still doesn't work. When I type in {=MRAND(5,,15)}
in the formula bar it just gives me ###
or just show the formula in the cell.

At this point i'd settle for a vb solution
instead of an addin.

I click on tools then addins then I click
on the box for morefunc (add in functions)
Then I click on OK then I get nothing.

When the other add-ins are highlighted, there is a description at the bottom of the add-in, when morefunc is highlighted there is no description at the bottom.

Could that be a problem?

Enter in A1...

=EVAL(1+5)

What result do you get?
 
Upvote 0
Hi jmcmahon:

If you have successfully installed the MoreFunc, you enter the following formula ...

=MRAND(5,,15)

This is an array formula, and is to be entered with CTRL+SHIFT+ENTER rather than with simply ENTER. The curly brackets are not to be entered manually, those are entered by the system, when the formula is entered as an array formula.

I hope it makes sense. If you need to discuss this further, please post back and let us take it from there.
 
Upvote 0
Hello Jm:
If your having trouble with a formula soluton here's a VBA solution for you:

Public Sub RandNum()
Randomize
Cells.Clear
For Each c In Range("A3:A7")
TryAgain: c.Value = (Int((15 * Rnd) + 1))
If Not Range("A2:A" & c.Row - 1).Find(c.Value, LookIn:=xlValues) Is Nothing Then GoTo TryAgain
Next c
End Sub

just paste this in your VBA window and your done.
 
Upvote 0

Forum statistics

Threads
1,214,544
Messages
6,120,126
Members
448,947
Latest member
test111

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