Open office calc combinations

dfdfdfdf -  
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   -
Hello,

I would like to generate all the combinations of 5 digits out of 50 in Excel. Could you help me?
I don't know anything about it, and I don't know how to create or run a macro.
Thank you.

6 réponses

via55 Posted messages 14730 Registration date   Status Membre Last intervention   2 755
 
Hello

Here it is
https://mon-partage.fr/f/UzoSeFy1/
Obviously, the longer the list of numbers in column A, the longer the macro takes to execute

Best regards
Via

--
"Imagination is more important than knowledge." A. Einstein
1
GrigoriPerelman
 
Thank you very much, however I am unable to execute the macro. Could you please check that it works well? Thank you in advance

and wow, beautiful program
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588
 
Hello, I feel like the code only returns a portion of the solutions, those where the numbers (a, b, c, d, e) are ordered according to the list.
0
via55 Posted messages 14730 Registration date   Status Membre Last intervention   2 755
 
It's more complicated
I'll try to take a look at this in my spare time

--
"Imagination is more important than knowledge." A. Einstein
1
GrigoriPerelman Posted messages 7 Status Membre 19
 
Sorry, I can't share my email or personal messages.
0
GrigoriPerelman Posted messages 7 Status Membre 19
 
on the other hand, I cannot manage to run the macro, are you sure it works
and could you please tell me how to launch it


thank you again for your consideration
0
GrigoriPerelman Posted messages 7 Status Membre 19
 
I would be very grateful if you could help me make the small modifications I just mentioned.


Thank you so much, Via55
0
GrigoriPerelman Posted messages 7 Status Membre 19
 
Forget my request for modification, I just want to make the program work but it doesn't!
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > GrigoriPerelman Posted messages 7 Status Membre
 
I just had to open the file with Excel and then press ctrl-t.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 588
 
Hello, what kind of result are you expecting?
0
dfdfdfdf
 
I would like to obtain a combination of 5 numbers from 50 arranged by line and without repetition
for example
1 2 3 4 5
5 50 4 12 9
...

There are more than 2 million possible combinations, but I don't know how to obtain them in Excel, I'm not familiar with it at all.
0
dfdfdfdf
 
If someone manages to create an easily executable program, it would be cool, even though I don't believe it too much given the difficulty of the task.
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > dfdfdfdf
 

Private Sub kombi() Dim f As Worksheet, nlig As Long, i1 As Integer, i2 As Integer, i3 As Integer, i4 As Integer, i5 As Integer Set f = ThisWorkbook.Sheets("combi") nlig = 1 For i1 = 1 To 50 For i2 = 50 To i1 + 1 Step -1 For i3 = i2 + 1 To 50 For i4 = 50 To i3 + 1 Step -1 For i5 = i4 + 1 To 50 f.Cells(nlig, 1) = i1 f.Cells(nlig, 2) = i2 f.Cells(nlig, 3) = i3 f.Cells(nlig, 4) = i4 f.Cells(nlig, 5) = i5 nlig = nlig + 1 Next i5 Next i4 Next i3 Next i2 Next i1 End Sub 
0
dfdfdfdf
 
Thank you, but what should I do with this code to get my combinations?
I don't know anything about it.
0
via55 Posted messages 14730 Registration date   Status Membre Last intervention   2 755
 
Hello

Here it is:
https://mon-partage.fr/f/3RHZ5m9V/
The results are displayed in 3 columns due to the number exceeding the number of cells in height in Excel

Best regards
Via

--
"Imagination is more important than knowledge." A. Einstein
0
dfdfdfdf
 
Thank you very much, but could you help me to put a number in each cell only, please?
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588 > dfdfdfdf
 
Why are you doing this exercise?
0
dfdfdfdf
 
I wish to establish this program in order to adapt it for throws for a study I am conducting.
0
dfdfdfdf
 
however, I would prefer to get one number per cell and not a draw per cell. Could you modify your program via 55 so that each cell contains a number
Best regards
0
dfdfdfdf
 
I don't know if my request is clear.. basically, I would like to do the same thing that via55 did but for a combination, I would like to have each of the numbers in the combination in different columns.
0
via55 Posted messages 14730 Registration date   Status Membre Last intervention   2 755
 
Re

Replace the macro with this one
Sub combi() y = 1 For a = 1 To 46 For b = a + 1 To 47 For c = b + 1 To 48 For d = c + 1 To 49 For e = d + 1 To 50 x = x + 1 If x > 1000000 Then x = 1: y = y + 7 Cells(x, y) = a Cells(x, y + 1) = b Cells(x, y + 2) = c Cells(x, y + 3) = d Cells(x, y + 4) = e Next Next Next Next Next End Sub


From another sheet, run the macro from the Developer ribbon - Macros - combi - Run
and be patient: the macro takes several minutes to execute given the number of writes to be done.
0
dfdfdfdf
 
Could you do it? An error message appears when I try to do it.
Best regards
0
dfdfdfdf
 
ah no, it's all good, thanks a lot
0
GrigoriPerelman
 
Hello, could you help me now to create a program that is practically similar but with constraints:

1) I want to provide a list of numbers

2) to make a combination of 5 digits from those I would have listed
-No repetition of the same digit in a combination
generating only combinations where the sum of the 5 digits is between 130 and 160
And that these combinations have a gap between each digit that I would determine, for example, we have a combination a b c d e I want that a+b+c+d+e = [130;160] and that b-a =[5;10], c-a=[12-14], d-a.., e-a.., etc


Thank you in advance for the time you will be able to allocate, and I imagine this will be quite lengthy

Best regards
0
via55 Posted messages 14730 Registration date   Status Membre Last intervention   2 755
 
Hello

Yes, the macro works but depending on the numbers and the entered min and max conditions, there may be no solution at all
So what do you mean by I can't execute the macro, : can't you run it or does nothing come out?

It is normal for the solutions to be ordered according to the numbers in the list since the macro reads them in order so that none is forgotten, that the same number is not taken into account twice in the same solution, and that all combinations are considered, so I don't see why only part of the solutions would be returned

--
"Imagination is more important than knowledge." A. Einstein
0
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   1 588
 
By "gap between each number," I understood the absolute value of the difference.
0
GrigoriPerelman
 
nothing comes out
0
GrigoriPerelman
 
Basically, this program is really perfect, but I would just like to have absolute value differences and be able to provide different lists of numbers for a, b, c, d, and e

and that it should execute as well, please

thanks again !!
0
GrigoriPerelman Posted messages 7 Status Membre 19
 
I would also like to provide a list of possible deviations, for example
b-a can be 3; 4; 6; 9; 12, etc.
0