random generation of whole numbers without duplication

brad kelly

New Member
Joined
Nov 16, 2005
Messages
1
Hi,

I would like to randomly generate 10 numbers between 1-750, without duplication. Thanks for any help you are able to lend.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try this code that I saved for future reference a while back - not written by me. It was written By DRJ aka Jacob

Is Jacob still around the board these days?


Code:
Option Explicit 

Sub RandomNumber() 

Dim Lowest              As Long 
Dim Highest             As Long 
Dim x                   As Long 
Dim y                   As Long 
Dim Total               As Long 
Dim ChoiceTemp          As Long 
Dim Choice()            As Long 
Dim Repeat              As Boolean 

    Application.ScreenUpdating = False 

    Lowest = 1 
    Highest = InputBox("what is the highest number?") 
    Total = InputBox("How many combinations do you want") 
    
ReDim Choice(1 To Total) 
        
    For x = 1 To Total 
a: 
        Randomize 
        Repeat = False 
        ChoiceTemp = Int((Highest + 1 - Lowest) * Rnd + Lowest) 
        For y = 1 To Total 
            If Choice(y) = ChoiceTemp Then 
                Repeat = True 
                Else 
            End If 
        Next y 
        If Repeat = True Then 
            GoTo a: 
            Else 
            Choice(x) = ChoiceTemp 
        End If 
    Next x 
    For x = 1 To Total 
        Sheets("Sheet1").Range("A" & x).Value = Choice(x) 
    Next 
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,875
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