Lottery Combinations

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Hello,</SPAN></SPAN>

I need a lottery generator that can pick few numbers from each group to make all possible sets of combinations, layout can be different if require to be fit for the macro to work no problem.
</SPAN></SPAN>

Example.... 2num from Group1, 2num from Group2, 1num from Group3
</SPAN></SPAN>


Book1
ABCDEFGHI
1Pink NumPink NumPink Num
2221
3Group1Group2Group3n1n2n3n4n5
41213113222535
52223215212234
63233323232433
742434
852535
9
10
11
12
13
14
15
Sheet1


Thank you all
</SPAN></SPAN>

Excel 2000
</SPAN></SPAN>
Regards,
</SPAN></SPAN>
Moti
</SPAN></SPAN>
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I searched in Mr.Excel and Google but did not find any solution for what I am looking for. Please help. Thank you all.
 
Upvote 0
=randbetween($A4,$A8)

This will get you one random number between the value in A4 and A8.
the formula can easily be amended to get numbers from column B or C.
 
Last edited:
Upvote 0
=randbetween($A4,$A8)

This will get you one random number between the value in A4 and A8.
the formula can easily be amended to get numbers from column B or C.
petertenthije, thank you, </SPAN></SPAN>I really want to be generated all possible combinations which could be made picking 2 numbers from group1, 2 numbers from group2 & 1 number from group3 and non of them should be repeated. </SPAN></SPAN>

I guess there must be 500 total not repeated combinations making as shown in a set of 5 numbers "=COMBIN(5,2)*COMBIN(5,2)*COMBIN(5,1)"=500 sets could be...
</SPAN></SPAN>

I think it have to be a VBA solution.
</SPAN></SPAN>
 
Upvote 0
Searching in the MrExcel forums found this thread which seems to my it is a solution I am looking for, but when I run the code produce 500 sets with 5 alphabets in the sheet solutions. Need help could it be converted in really numbers in to 5 columns separately...
https://www.mrexcel.com/forum/excel...ups-whose-sum-specific-range.html#post4920893


Book1
ABCD
1Lower Sum5
2Upper Sum165
3Group NameABC
4Elements From Group221
5Group Members12131
622232
732333
842434
952535
Problem


Code..
Code:
Public Sub FindCombos()

Dim setSize As Long
Dim lastCol As Long
Dim thisCol As Long
Dim elCount As Long
Dim i As Long
Dim j As Long
Dim total As Long
Dim solution As String
Dim selectedCells() As Range
Dim rowStart() As Long
Dim setCount() As Long
Dim lastRow As Long
Dim nextRow As Long
Dim allOK As Boolean

' Clear out the solutions
Sheets("Solutions").Cells.ClearContents

' Find the last group and the number of elements we're going to pick
lastCol = Cells(3, Columns.Count).End(xlToLeft).Column
setSize = Application.WorksheetFunction.Sum(Range(Cells(4, 2), Cells(4, lastCol)))

' Set up the arrays
ReDim selectedCells(setSize) As Range
ReDim rowStart(lastCol) As Long
ReDim setCount(lastCol) As Long

' Set the initial selection
i = 1
Set selectedCells(0) = Cells(1, 1)
For thisCol = 2 To lastCol
    For elCount = 1 To Cells(4, thisCol).Value
        Set selectedCells(i) = Cells(4 + elCount, thisCol)
        i = i + 1
    Next elCount
Next thisCol

' Uniquely name each element in the groups
rowStart(2) = 97
For thisCol = 2 To lastCol
    lastRow = Cells(Rows.Count, thisCol).End(xlUp).Row
    setCount(thisCol) = lastRow - 4
    If thisCol < lastCol Then rowStart(thisCol + 1) = rowStart(thisCol) + setCount(thisCol)
Next thisCol

' Next solution row
nextRow = 1

' Keep going until we've exhausted all possibilities
Do While True
    ' Check the current total
    total = 0
    For i = 1 To setSize
        total = total + selectedCells(i).Value
    Next i
    
    ' Total is in range?
    If total >= Cells(1, 2).Value And total <= Cells(2, 2).Value Then
        ' Generate the solution
        solution = ""
        For i = 1 To setSize
            solution = solution & Chr$(rowStart(selectedCells(i).Column) + selectedCells(i).Row - 5)
        Next i
        
        ' Print the solution on the solution sheet
        Sheets("Solutions").Cells(nextRow, 1).Value = solution
        nextRow = nextRow + 1
    End If
    
    ' Tick over to the next selection
    i = setSize
    Do While True
        ' Move the cell down
        Set selectedCells(i) = selectedCells(i).Offset(1, 0)
        
        ' OK?
        If selectedCells(i).Value = "" Then
            ' Move this back to the top
            Set selectedCells(i) = Cells(5, selectedCells(i).Column)
            
            ' Move to the previous cell and move that
            i = i - 1
        Else
            allOK = True
            ' Adjust all other cells
            If i < setSize Then
                For j = i + 1 To setSize
                    If selectedCells(j).Column = selectedCells(i).Column Then
                        Set selectedCells(j) = selectedCells(j - 1).Offset(1, 0)
                        If selectedCells(j).Value = "" Then
                            i = i - 1
                            allOK = False
                            Exit For
                        End If
                    End If
                Next j
            End If
            
            ' Column exhausted
            If allOK Or i = 0 Then Exit Do
            
            ' Reset column?
            If selectedCells(i).Column <> selectedCells(i + 1).Column Then
                Set selectedCells(i + 1) = Cells(5, selectedCells(i + 1).Column)
                For j = i + 2 To setSize
                    If selectedCells(j).Column = selectedCells(j - 1).Column Then
                        Set selectedCells(j) = selectedCells(j - 1).Offset(1, 0)
                    End If
                Next j
            End If
        End If
        
        ' Done?
        If i = 0 Then Exit Do
    Loop
    
    ' Finished?
    If i = 0 Then Exit Do
Loop

End Sub

Getting these results...


Book1
A
1abfgk
2abfgl
3abfgm
4abfgn
5abfgo
6abfhk
7abfhl
8abfhm
9abfhn
10abfho
11abfik
12abfil
13abfim
14abfin
15abfio
16abfjk
17abfjl
18abfjm
19abfjn
20abfjo
21abghk
22abghl
23abghm
24abghn
25abgho
Solutions


Result Require like This....


Book1
CDEFG
1n1n2n3n4n5
212212231
312212232
412212233
512212234
612212235
712212331
812212332
912212333
1012212334
1112212335
1212212431
1312212432
1412212433
Solutions


Thank you all
Regards,
Moti
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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