S.H.A.D.O.
Well-known Member
- Joined
- Sep 6, 2005
- Messages
- 1,915
Good evening,
I would like to cycle through all the combinations and count the sum of the ODD numbers AND the sum of the EVEN numbers within each of the combination please.
I know the following:-
The LOWEST sum of ODD will be 0.
The LOWEST sum of EVEN will be 0.
The HIGHEST sum of ODD will be 264.
The HIGHEST sum of EVEN will be 258.
So, for example:-
06 24 30 39 46 49 = Odd 88 & Even 106
02 16 25 32 45 48 = Odd 70 & Even 98
03 20 27 29 36 47 = Odd 106 & Even 56
07 14 22 23 31 44 = Odd 61 & Even 80
So I will end up with the numbers from 0 to 264 in column A, the total for each of the sums of ODD numbers in column B and the total for each of the sums of EVEN numbers in column C.
Here is what I have so far but now I am stuck:-
Thanks in advance.
I would like to cycle through all the combinations and count the sum of the ODD numbers AND the sum of the EVEN numbers within each of the combination please.
I know the following:-
The LOWEST sum of ODD will be 0.
The LOWEST sum of EVEN will be 0.
The HIGHEST sum of ODD will be 264.
The HIGHEST sum of EVEN will be 258.
So, for example:-
06 24 30 39 46 49 = Odd 88 & Even 106
02 16 25 32 45 48 = Odd 70 & Even 98
03 20 27 29 36 47 = Odd 106 & Even 56
07 14 22 23 31 44 = Odd 61 & Even 80
So I will end up with the numbers from 0 to 264 in column A, the total for each of the sums of ODD numbers in column B and the total for each of the sums of EVEN numbers in column C.
Here is what I have so far but now I am stuck:-
Code:
Option Explicit
Option Base 1
Const MinA As Integer = 1
Const MaxF As Integer = 49
Sub Sum_Of_ODD_And_EVEN_Numbers()
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, F As Integer
Dim i As Integer
Dim nType(0 To 264) As Double
Dim sum As Long
Dim results(49) As Long
Dim nTypeTotal As Long
With Application
.ScreenUpdating = False: .Calculation = xlCalculationManual: .DisplayAlerts = False
End With
With Sheets("Results").Select
Range("A:C").ClearContents
Range("A1").Select
For i = LBound(nType) To UBound(nType)
nType(i) = 0
Next i
For i = MinA To MaxF
results(i) = i Mod 2
Next i
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
sum = results(A) + results(B) + results(C) + results(D) + results(E) + results(F)
nType(sum) = nType(sum) + 1
Next F
Next E
Next D
Next C
Next B
Next A
nTypeTotal = ActiveCell.Row
With ActiveCell
For i = LBound(nType) To UBound(nType)
.Offset(i - LBound(nType), 0).Value = i
.Offset(i - LBound(nType), 1).Value = nType(i)
Next i
.Offset(i - LBound(nType), 1).FormulaR1C1 = "=Sum(R" & nTypeTotal & "C:R[-1]C)"
End With
End With
With Application
.DisplayAlerts = True: .Calculation = xlCalculationAutomatic: .ScreenUpdating = True
End With
End Sub
Thanks in advance.