S.H.A.D.O.
Well-known Member
- Joined
- Sep 6, 2005
- Messages
- 1,915
Good morning,
I have really been trying to write some VBA code for weeks now but to no avail.
I basically want to output combinations [6 numbers in each combination] based on certain criteria.
So if I ONLY wanted to output combinations with 3 LOW numbers, 3 HIGH numbers, 3 ODD numbers, and 3 EVEN numbers using CASE statements, how would I do that please?
Here is some code [I have just used 12 numbers for my test but it will actually be more] I have been working on but I can't get even close to it outputting correctly [it outputs ALL the combinations!] . . .
Now the structure of this is 3333 [3 LOW, 3 HIGH, 3 ODD, 3 EVEN].
So what I would like is . . .
[1] An input box where I could input the 3333, or 1560, or 4224, or whatever distribution and it will output the combinations accordingly please.
[2] Output the combinations in individual cells rather than one cell separated with a "-".
Thanks in advance.
I have really been trying to write some VBA code for weeks now but to no avail.
I basically want to output combinations [6 numbers in each combination] based on certain criteria.
So if I ONLY wanted to output combinations with 3 LOW numbers, 3 HIGH numbers, 3 ODD numbers, and 3 EVEN numbers using CASE statements, how would I do that please?
Here is some code [I have just used 12 numbers for my test but it will actually be more] I have been working on but I can't get even close to it outputting correctly [it outputs ALL the combinations!] . . .
Code:
Option Explicit
Option Base 1
Const MinA As Integer = 1
Const MaxF As Integer = 12
Sub Selection()
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer
Dim IsWhatever As Long
Dim n(1 To 12) As Long ' IsWhatever ? (No = 0, Yes = 1).
Dim nWhatever(0 To 6) As Long ' Hold IsWhatever count.
Dim Total As Long
With Application
.ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
End With
Cells(1, 1).Select
For IsWhatever = 1 To UBound(n)
Select Case IsWhatever
Case 1, 2, 3, 4, 5, 6
n(IsWhatever) = 1
Case 7, 8, 9, 10, 11, 12
n(IsWhatever) = 1
Case 1, 3, 3, 7, 9, 11
n(IsWhatever) = 1
Case 2, 4, 6, 8, 10, 12
n(IsWhatever) = 1
Case Else
n(IsWhatever) = 0
End Select
Next IsWhatever
For A = MinA To MaxF - 5
For B = A + 1 To MaxF - 4
For C = B + 1 To MaxF - 3
For D = C + 1 To MaxF - 2
For E = D + 1 To MaxF - 1
For F = E + 1 To MaxF
With Application.WorksheetFunction
ActiveCell.Value = .Text(A, "00") & "-" _
& .Text(B, "00") & "-" _
& .Text(C, "00") & "-" _
& .Text(D, "00") & "-" _
& .Text(E, "00") & "-" _
& .Text(F, "00")
ActiveCell.Offset(1, 0).Select
End With
Next F
Next E
Next D
Next C
Next B
Next A
With Application
.DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
End With
End Sub
Now the structure of this is 3333 [3 LOW, 3 HIGH, 3 ODD, 3 EVEN].
So what I would like is . . .
[1] An input box where I could input the 3333, or 1560, or 4224, or whatever distribution and it will output the combinations accordingly please.
[2] Output the combinations in individual cells rather than one cell separated with a "-".
Thanks in advance.