VBA random numbers generator with required sum </SPAN></SPAN>
I need a VBA that can choose 7 random numbers out of 3 numbers, which are listed in the cells A4:A6 </SPAN></SPAN>
Create for example 50 random in the cells F4:L53 without repetitions (I mean 2 rows should not be the same) as per each row sum is as assigned in the column M, is it possible? (Sum can be vary from 0 to 14)</SPAN></SPAN>
In the example below some set are shown with row sum=7 </SPAN></SPAN>
Thank you all</SPAN></SPAN>
Excel 2000</SPAN></SPAN>
Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
I need a VBA that can choose 7 random numbers out of 3 numbers, which are listed in the cells A4:A6 </SPAN></SPAN>
Create for example 50 random in the cells F4:L53 without repetitions (I mean 2 rows should not be the same) as per each row sum is as assigned in the column M, is it possible? (Sum can be vary from 0 to 14)</SPAN></SPAN>
In the example below some set are shown with row sum=7 </SPAN></SPAN>
Book1 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | |||
1 | |||||||||||||||
2 | |||||||||||||||
3 | Total Numbers | n1 | n2 | n3 | n4 | n5 | n6 | n7 | SUM | ||||||
4 | 0 | 2 | 1 | 0 | 0 | 1 | 1 | 2 | 7 | ||||||
5 | 1 | 1 | 1 | 1 | 1 | 2 | 1 | 0 | 7 | ||||||
6 | 2 | 0 | 1 | 1 | 2 | 1 | 2 | 0 | 7 | ||||||
7 | 1 | 2 | 0 | 0 | 2 | 1 | 1 | 7 | |||||||
8 | 1 | 1 | 2 | 0 | 1 | 0 | 2 | 7 | |||||||
9 | 2 | 0 | 1 | 1 | 2 | 0 | 1 | 7 | |||||||
10 | 0 | 2 | 1 | 1 | 0 | 1 | 2 | 7 | |||||||
11 | 0 | 1 | 1 | 1 | 1 | 1 | 2 | 7 | |||||||
12 | 1 | 1 | 1 | 2 | 0 | 1 | 1 | 7 | |||||||
13 | 0 | 2 | 1 | 1 | 1 | 2 | 0 | 7 | |||||||
14 | 1 | 1 | 2 | 2 | 0 | 0 | 1 | 7 | |||||||
15 | 1 | 0 | 2 | 0 | 0 | 2 | 2 | 7 | |||||||
16 | 1 | 0 | 0 | 1 | 2 | 1 | 2 | 7 | |||||||
17 | 1 | 0 | 1 | 2 | 1 | 1 | 1 | 7 | |||||||
18 | 2 | 1 | 1 | 1 | 1 | 0 | 1 | 7 | |||||||
19 | 1 | 2 | 0 | 1 | 2 | 1 | 0 | 7 | |||||||
20 | 1 | 1 | 0 | 2 | 1 | 1 | 1 | 7 | |||||||
21 | 1 | 2 | 1 | 2 | 0 | 1 | 0 | 7 | |||||||
22 | 0 | 1 | 1 | 1 | 2 | 1 | 1 | 7 | |||||||
23 | 0 | 2 | 0 | 1 | 1 | 1 | 2 | 7 | |||||||
24 | 1 | 1 | 1 | 2 | 1 | 1 | 0 | 7 | |||||||
25 | 0 | 0 | 1 | 1 | 2 | 2 | 1 | 7 | |||||||
26 | 1 | 0 | 2 | 1 | 0 | 1 | 2 | 7 | |||||||
27 | 1 | 1 | 1 | 1 | 1 | 2 | 0 | 7 | |||||||
28 | 1 | 2 | 2 | 0 | 0 | 1 | 1 | 7 | |||||||
29 | 1 | 0 | 1 | 1 | 2 | 1 | 1 | 7 | |||||||
30 | 0 | 1 | 1 | 2 | 1 | 1 | 1 | 7 | |||||||
31 | 1 | 2 | 1 | 1 | 1 | 0 | 1 | 7 | |||||||
32 | 0 | 1 | 1 | 2 | 0 | 1 | 2 | 7 | |||||||
33 | 1 | 2 | 0 | 2 | 1 | 1 | 0 | 7 | |||||||
34 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 7 | |||||||
35 | 2 | 1 | 1 | 1 | 0 | 0 | 2 | 7 | |||||||
36 | 2 | 2 | 1 | 0 | 1 | 0 | 1 | 7 | |||||||
37 | 1 | 1 | 1 | 0 | 2 | 1 | 1 | 7 | |||||||
38 | 0 | 1 | 1 | 1 | 2 | 0 | 2 | 7 | |||||||
39 | 0 | 2 | 0 | 2 | 0 | 2 | 1 | 7 | |||||||
40 | 1 | 1 | 1 | 2 | 0 | 0 | 2 | 7 | |||||||
41 | 1 | 1 | 1 | 1 | 0 | 2 | 1 | 7 | |||||||
42 | 2 | 0 | 2 | 1 | 1 | 1 | 0 | 7 | |||||||
43 | 1 | 0 | 2 | 2 | 1 | 1 | 0 | 7 | |||||||
44 | 2 | 1 | 0 | 2 | 0 | 1 | 1 | 7 | |||||||
45 | 1 | 1 | 2 | 1 | 0 | 2 | 0 | 7 | |||||||
46 | 2 | 2 | 1 | 0 | 0 | 1 | 1 | 7 | |||||||
47 | 1 | 1 | 2 | 1 | 0 | 1 | 1 | 7 | |||||||
48 | 1 | 0 | 2 | 1 | 1 | 0 | 2 | 7 | |||||||
49 | 1 | 1 | 2 | 1 | 1 | 1 | 0 | 7 | |||||||
50 | 2 | 1 | 2 | 0 | 1 | 0 | 1 | 7 | |||||||
51 | 2 | 2 | 1 | 0 | 0 | 0 | 2 | 7 | |||||||
52 | 1 | 2 | 1 | 1 | 0 | 2 | 0 | 7 | |||||||
53 | 1 | 1 | 1 | 0 | 1 | 2 | 1 | 7 | |||||||
Sheet1 |
Thank you all</SPAN></SPAN>
Excel 2000</SPAN></SPAN>
Regards,</SPAN></SPAN>
Moti</SPAN></SPAN>
Last edited: