logo elektroda
logo elektroda
X
logo elektroda

Writing a Macro in Excel 2013 for Generating All Combinations of 4 Numbers from a Set of 6

26808 19
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 13899817
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #2 13900059
    adamas_nt
    Moderator of Programming
    Attached is a solution without the use of VBA, using the LOS function and an auxiliary line. The probability of repetition exists only in theory.
  • #3 13900200
    Anonymous
    Level 1  
  • #4 13902128
    adamas_nt
    Moderator of Programming
    Once you have written it down, use it as an auxiliary table.
    E.g:
    enter the schedule in L1 :O 15
    in H1 type =SHIFT($A$1;0;L1-1) and copy 4 to the right and 15 down
    in h16 =SHIFT($A$2;0;L1-1) and copy 4 right and 15 down
    etc, etc

    Writing a Macro in Excel 2013 for Generating All Combinations of 4 Numbers from a Set of 6

    Finally, you can write a simple macro using this layout: a 'Do' loop with a counter according to column A, inside which place a double 'For' (outer 15 steps, inner 4) with the assignment: Cells(x + ((counter 'Do' - 1)*15), y) = Cells(counter'To', number_from_table)
  • #5 13902469
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #6 13905217
    adamas_nt
    Moderator of Programming
    ZbiguZbigu wrote:
    I don't have time to learn it now
    Well, the forum was created for those who don't waste their time...

    While having my morning coffee, I had the urge to find a solution without a schedule, and I ended up in a loop
    Code: text
    Log in, to see the code
    Maybe it will be useful to those looking for similar issues.

    With a table (which, by the way, I copied with an error /fig/), in the arrangement described above, the matter is solved by this macro (if I started, let me finish)
    Code: text
    Log in, to see the code
    And that would be it in terms of cash. However, I suggest you try your hand at it. It's not painful...
  • #7 13905436
    Anonymous
    Level 1  
  • #8 13907957
    adamas_nt
    Moderator of Programming
    ZbiguZbigu wrote:
    unfortunately this macro doesn't work
    Because it's written in spreadsheet code. If you placed in a module, change to
    Code: text
    Log in, to see the code
    or something similar.
  • #9 14590682
    wachuwach
    Level 2  
    Hello,

    I have a similar problem. It looks like this:
    I have x classes from 1 to n. Each one must be compared without repetition.
    I would be grateful if someone would describe and explain the general algorithm to me.
    I will implement it in C++.

    Regards
  • ADVERTISEMENT
  • #10 14590737
    -psiak-
    Level 32  
    wachuwach wrote:
    ... compare each one with each other ...

    So what's the problem?
    In the loop after I from 1 to n you compare tb[I] with tb[I]
  • #11 14592442
    wachuwach
    Level 2  
    the problem is that it is in one array

    for example, I have 6 classes (elements) {1,2,3,4,5,6} and let's say I want to display them like this:

    1.2
    1.3
    1.4
    1.5
    1.6
    2.3
    2.4
    2.5
    2.6
    3.4
    3.5
    3.6
    4.5
    4.6
    5.6

    I'm sure there is a simple algorithm for this, but I can't think of anything.
    Of course, this should be for any number of classes.

    Happy Christmas ;)

    Added after 29 [minutes]:

    I did :D Simpler than I thought.

    [syntax=cpp-qt]
    int liczba_klas = 7;
    int k, l;
    k = l = 0;
    for (k; k < liczba_klas; k++)
    {
    l = k + 1;
    for (l; l < liczba_klas; l++)
    {
    cout
  • #12 14592671
    -psiak-
    Level 32  
    First of all, it is not called everyone with each other without repetitions, and all pairs without repetitions.
    Secondly, don't use i++ where you can use ++i, it will backfire
    Third, don't use single 'l' characters to name variables, it will backfire
    Fourth, if you use the benefits of C++, you will get:
    [syntax=cpp]for(int k=0;k
  • #13 15092011
    oceanic24
    Level 2  
    adamas_nt wrote:
    Attached is a solution without the use of VBA, using the LOS function and an auxiliary line. The probability of repetition exists only in theory.



    Hello, I am looking for a ready-made program that will show me all possible combinations of numbers.
    Can someone please make all combinations of 3 numbers in Excel from the pool of 42 numbers and 49 and the same only from 2 numbers?

    Someone here added an attachment, but it is 5 numbers out of 10 and I don't know how to modify it, as I don't know much about this program.

    I'm even ready to buy such a ready-made project on Allegro if it would take a lot of work to create something like that.

    I'm talking about :
    (3) of 42 numbers of all combinations
    (3) of 49 numbers of all combinations
    and the same, but only (2) from 42 and 49


    Greetings and I'm waiting for an answer from someone who knows this program and could help me.

    Attached is the project added by adamas_nt.
  • #14 15092154
    -psiak-
    Level 32  
    Either learn the basics of the tool you are using or forget about the project.

    Code: VB.net
    Log in, to see the code


    Code: VB.net
    Log in, to see the code
  • #15 15092259
    JRV
    VBA, Excel specialist
    -psiak- wrote:
    For i = 1 To 42
    For j = i+1 To 42

    Myslim że [code:1] For i = 1 To 42
    For j = i+1 To 41[/code:1]
  • #16 15092275
    -psiak-
    Level 32  
    JRV wrote:
    I think so
     For i = 1 To 42
        For j = i+1 To 41
    You're thinking wrong, if so:
    Code: VB.net
    Log in, to see the code
    but there is no point in doing it anyway, because for i=42 the loop after j will be from 43 to 42, so it will not be executed.
  • #17 15092811
    oceanic24
    Level 2  
    Unfortunately, I'm too green to even know where to paste these codes in Excel. I wanted to edit the file as provided by the author above. Everything is fine, but instead of 42 there are 10 numbers and not yet in the order, only from 11-20.
    I wanted to splurge every payday and play so that there was a 100% chance that I would hit three. According to the lotto website, the probability is 1:128, which means I would have to spend about PLN 160 on mini lotto tickets.
  • ADVERTISEMENT
  • #18 15093730
    -psiak-
    Level 32  
    And did you try to come to the painting forum and say: - Unfortunately, I'm too green to... so who will paint my apartment?
  • #19 15098669
    oceanic24
    Level 2  
    I was looking for guides on the Internet on how to make all combinations of threes in mini lotto in Excel. So that I can be 100% sure that I will hit the three-pointer. There are no such guides anywhere, they are probably only for C++, but it is a language for professional IT specialists and an ordinary green smith certainly won't be able to master it in one day.
    On Chomikuj, all combinations of the big lottery are available for download, i.e. almost 14 million combinations, but this is neither achievable nor profitable even for a millionaire when there is no large jackpot. Unless, during a large jackpot, he will have a team that will hand over blank forms to terminals all over Poland if they can keep up with such a large number of tickets.

    The probability of hitting three in the mini lotto is from 1 to 128.

    This means you need to bet on 128 combinations. So, counting one ticket for 1.25, you have to spend PLN 160 to have a guarantee of hitting three.
  • #20 15098704
    -psiak-
    Level 32  
    Learn any programming language and do this project yourself, especially since this project does not require any special skills. Or simply order a project.

Topic summary

A user seeks assistance in writing a macro in Excel 2013 to generate all unique combinations of 4 numbers from a set of 6 numbers, specifically for Lotto results. The input data is located in cells A1 to F1, and the desired output should be displayed in columns H to K, continuing for subsequent rows. Several responses suggest alternative methods, including using auxiliary tables and VBA code. Some users provide partial code snippets and logic for creating the macro, while others express the need for a complete solution without prior programming knowledge. The discussion highlights the challenges of generating combinations and the desire for a straightforward implementation in Excel.
Summary generated by the language model.
ADVERTISEMENT