LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 394
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I produce consecutive invoice numbers in Excel? John Z Excel Worksheet Functions 4 December 11th 09 07:03 AM
How do I produce Automatic Quotation Numbers in Excel? flymeoutofhere Excel Discussion (Misc queries) 2 September 25th 06 12:16 PM
Delete Numbers and Produce a List Paul Black Excel Programming 6 October 27th 05 12:26 PM
Non-random numbers generated by excel's data analysis random gener Allie Excel Worksheet Functions 10 September 17th 05 06:19 AM
Non-random numbers generated by excel's data analysis random gener Harlan Grove Excel Discussion (Misc queries) 2 September 13th 05 04:06 PM


All times are GMT +1. The time now is 08:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"