If I understand your requirements ???:
A) You want to randomly generate 6 unique single-digit numbers per row.
B) The first number must be non-zero; the remaining numbers may fall between 0 and 9.
C) Each of the above is added to a "10's" digit corresponding to its position (numbered 0,1,2,3,4,5).
...So {3,4,2,8,5,1} becomes {03,14,22,38,45,51}
The following code generates the described output, placing it in a Named Range called Output_Range. This range may be any number of rows, but must be 6 columns wide. NOTE - If you don't want to deal with a Named Range, you can replace the RED TEXT with a standard range reference eg. "A9:F18"
Sub Generate_Random6x2s()
Dim i As Long, k As Long, r As Long
Dim CHK(9) As Long, OUTPUT()
With Range("Output_Range")
ReDim OUTPUT(1 To .Rows.Count, 1 To 6)
For i = 1 To UBound(OUTPUT, 1)
r = [RANDBETWEEN(1,9)]
CHK(r) = i
OUTPUT(i, 1) = r
For k = 2 To 6
Do
r = [RANDBETWEEN(0,9)]
Loop While CHK(r) = i
CHK(r) = i
OUTPUT(i, k) = r + 10 * (k - 1)
Next
Next
.Value = OUTPUT()
End With
End Sub
Row\Col |
A |
B |
C |
D |
E |
F |
8 |
Output_Range |
|
|
|
|
|
9 |
03 |
19 |
27 |
36 |
41 |
50 |
10 |
05 |
13 |
21 |
38 |
40 |
56 |
11 |
04 |
10 |
23 |
31 |
46 |
58 |
12 |
02 |
16 |
23 |
30 |
44 |
58 |
13 |
04 |
11 |
28 |
30 |
45 |
52 |
14 |
06 |
15 |
24 |
31 |
42 |
50 |
15 |
03 |
17 |
26 |
35 |
41 |
54 |
16 |
06 |
18 |
27 |
35 |
42 |
59 |
17 |
07 |
18 |
20 |
32 |
41 |
55 |
18 |
09 |
12 |
23 |
31 |
47 |
58 |
I await your response...
Bookmarks