Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Produce Random Numbers
Good evening,
I am trying to write a program that outputs 5 random numbers without repetition from 50 numbers. The number of combinations to be produced is in worksheet "Random Numbers" and in cell "P3". The code below works as far as the above is concerned. Sub Random_Numbers_Generator() Dim nDrawnMain As Long Dim nFromMain As Long Dim nDrawnLucky As Long Dim nFromLucky As Long Dim nComb As Long Dim myMain() As Variant Dim myLucky() As Variant Application.ScreenUpdating = False Application.Calculation = xlCalculationManual Application.DisplayAlerts = False nDrawnMain = 5 nFromMain = 50 nDrawnLucky = 2 nFromLucky = 9 Worksheets("Random Numbers").Select With ActiveSheet Range("A1:J65536").Select Selection.ClearContents ReDim myMain(1 To nFromMain) ReDim myLucky(1 To nFromLucky) ' nDrawn = .Range("N3").Value ' nFrom = .Range("O3").Value nComb = .Range("P3").Value End With For j = 1 To nComb For H = 1 To nFromMain myMain(H) = H Next H For k = 1 To nDrawnMain Randomize NewNumber: Number = Int(nFromMain * Rnd) + 1 If myMain(Number) = "" Then GoTo NewNumber Else Cells(j, k) = myMain(Number) myMain(Number) = "" End If Next k Next j Range("N3").Select Application.DisplayAlerts = True Application.Calculation = xlCalculationAutomatic Application.ScreenUpdating = True End Sub What I would like to add is to output 2 random numbers without repetition from 9 numbers. I would like to output these 2 extra numbers after it has produced the 5th number and skipped two cells to the right from the previous combination. Both these combinations are totally seperate from each other so could possibly have the same numbers in them. So basically, the program will produce two sets of random numbers without repetition:- The first being 5 numbers from 50 numbers. The second being 2 numbers from 9 numbers. The 5 numbers will be output in cells A1:E1 and the 2 numbers will be output in cells G1:H1. Thanks in advance, Paul |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I produce consecutive invoice numbers in Excel? | Excel Worksheet Functions | |||
How do I produce Automatic Quotation Numbers in Excel? | Excel Discussion (Misc queries) | |||
Delete Numbers and Produce a List | Excel Programming | |||
Non-random numbers generated by excel's data analysis random gener | Excel Worksheet Functions | |||
Non-random numbers generated by excel's data analysis random gener | Excel Discussion (Misc queries) |