PAB said:
Hi sss,
Is it not possible to amend the Macro by Defining the Different Groups?, then get the Macro to IGNORE Combinations that have MORE than 4 Numbers out of the 6 from ANY ONE Group. It would be nice to be able to do this.
All the Best
PAB
Hi PAB,
Private Function getGroups(A As Variant) As Integer
'input array is a an array(1 to 6) - this is a combination to be tested
'Array ColumnCount is a (1 to 5) array, each of its 5 items
'will represent number of occurances in corresponding column
'of your criteria grid
Dim ColumnCount(1 To 5) As Integer
Dim i&, Column&, ColumnsOccupied&
'initializing:
ColumnsOccupied = 0
For i = 1 To 5
ColumnCount(i) = 0
Next
For i = 1 To 6 'check all items of the input array: what column of a grid do they belong to:
Select Case A(i)
Case 1, 6, 11, 16, 21, 26, 31, 36, 41, 46: Column = 1
Case 2, 7, 12, 17, 22, 27, 32, 37, 42, 47: Column = 2
Case 3, 8, 13, 18, 23, 28, 33, 38, 43, 48: Column = 3
Case 4, 9, 14, 19, 24, 29, 34, 39, 44, 49: Column = 4
Case 5, 10, 15, 20, 25, 30, 35, 40, 45: Column = 5
End Select
ColumnCount(Column) = ColumnCount(Column) + 1
Next
For i = 1 To 5
A(i) = ColumnCount(i)
If A(i) <> 0 Then ColumnsOccupied = ColumnsOccupied + 1
Next
getGroups = ColumnsOccupied
'This function returns total number of columns occupied by a set
'that has been passed to function
'Also, it returns back an array of number of column occurances,
'e.g if a combination is 1,2,3,4,5,6
'and a test array Test(1)=1, Test(2)=2,...Test(6)=6, then
' HowManyColumns=getGroups(Test) call will result in
' 1. HowManyColumns variable will be equal to 5 (all 5 columns are occupied)
' 2. Array: Test(1)=2 (numbers 1 & 6 belong to the same column#1)
' Test(2)=1 (just ONE number, which is a "2" number belongs to the column #2)
' Test(3)=1
' Test(4)=1
' Test(5)=1
' Test(6)= Not Changed. Should be ignored, as we don't have Column #6
' If however, you change your criteria, and redesigne your grid to have
' 7 columns 7 number each, you have to change dimension of a input array.
' Test array has to have (1 to 7) size in that case. Even though your source
'combination has 6 number, you have to pass 7 values in order to be able to
'get back 7 values.
End Function
1. Define array like dim A(1 to 6) as integer
2.Start from the first line of your spreadsheet and go through
all draws that you have in it.
for i=1 to LastDraw'LastDraw ia a variable with the last draw number which you know for sure
...
next
3. Put code instead "...". This code will:
- assign array values to a draw numbers, like for i=1 to 6: A(i)=Cells(currentRow,currentCol+i)
-call GetGroups function and make a desision based on business rules you like.
ColumnsOccupied=GetGroups(A)
if ColumnsOccupied=1 then..... reject
or if ColumnsOccupied=2 or columnsoccupied=3 then....reject and so on.
Additional rules could be applied to the result array "A" which
after you called GetDgoups function contains return data. Not
the source data from the draws! Now it contains number of
each column occurances.
For example,
if ColumnOccupied>3 then
if a(1)=2 then .... reject
end if
Hope this is what you've asked for,
Good luck!
sss