SET OF 6 NUMBERS FROM 1-49

OWAIZ

Board Regular
Joined
Jun 20, 2002
Messages
89
Hi Champs,
A challenge for me, passing it to u, i want to generate a set of 6 numbers from 1-49. the set's should not be similar. and the numbers in the set should not repeat the same number.
for eg. 12345, 345673,

i think when i will run this combinations, i will get atleast 1 lakh combination of set..

waiting for ur kind help..

regards
owaiz
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You can try the following code. Its adapted off a post I made for another poster.
<pre>Option Base 1
Sub RandomNumberStrings()

Dim rndno As String, strg As String, msg1 As String
Dim r1() As String, r2() As String
Dim l As Integer, u As Integer, NoStr As Integer, SetCount As Integer
Dim i As Integer, j As Integer, k As Integer, m As Integer
Dim a As Variant

l = 1 'Low number in range
u = 49 'High number in range
SetCount = 10 '# of random number sets
NoStr = 6 '# of random numbers in sets
ReDim r1(NoStr)
ReDim r2(SetCount)
For i = 1 To SetCount
Do
For j = l To NoStr
Do
rndno = Int((u - l + 1) * Rnd + l)
For k = 1 To j
If rndno = r1(k) Then
Exit For
ElseIf k = j Then
Exit Do
End If
Next k
Loop
r1(j) = rndno
Next j
strg = Join(r1, ",")
ReDim r1(NoStr)
For m = 1 To i
If strg = r2(m) Then
Exit For
ElseIf m = i Then
Exit Do
End If
Next m
Loop
r2(i) = strg
Next i
For Each a In r2
msg1 = msg1 & a & Chr(10)
Next a
MsgBox msg1

End Sub</pre>
 
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,838
Members
449,343
Latest member
DEWS2031

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