I am using a program that was designed to create combinations of players, tally up some specific values, sum up those values and then write them to the spreadsheet once completed. That part of the program continues to work just fine. Now, I'm trying to add one more element to this program and can't get it to write to the spreadsheet correctly.
In short, I've created a new array called array_MaxPlayT. Based on my running "debug", I know that I am appropriately populating the array with the expected values. My problem seems to be getting the correct output written to the spreadsheet. Example: using DEBUG, I am able to tell that array_MaxPlayT(1) = 22, array_MaxPlayT(2) = 22, array_MaxPlayT(3) = 34, array_MaxPlayT(4) = 26, array_MaxPlayT(5) = 22, etc. However, only the value of 22 get written to the spreadsheet for each line and I don't understand why.
The code I'm using is below. The new code I inserted is highlighted in BOLD. Again, the original code still seems to work fine. I don't understand why the new array is only writing the one/same value for all combinations.
Any thoughts on how to make this work correctly would be appreciated.
In short, I've created a new array called array_MaxPlayT. Based on my running "debug", I know that I am appropriately populating the array with the expected values. My problem seems to be getting the correct output written to the spreadsheet. Example: using DEBUG, I am able to tell that array_MaxPlayT(1) = 22, array_MaxPlayT(2) = 22, array_MaxPlayT(3) = 34, array_MaxPlayT(4) = 26, array_MaxPlayT(5) = 22, etc. However, only the value of 22 get written to the spreadsheet for each line and I don't understand why.
The code I'm using is below. The new code I inserted is highlighted in BOLD. Again, the original code still seems to work fine. I don't understand why the new array is only writing the one/same value for all combinations.
Any thoughts on how to make this work correctly would be appreciated.
VBA Code:
' Following code sorts chart from top to bottom
Dim ws2 As Worksheet
Set ws2 = Worksheets("CommonData")
' Following code sorts chart from left to right
ws2.Sort.SortFields.Clear
ws2.Range("E3:X24").Sort Key1:=ws2.Range("E3:X3"), Order1:=xlAscending, Orientation:=xlLeftToRight
Dim lCombinations() As Long, lPairs() As Long, lNumbers() As Long, N As Long, r As Long, i As Long, j As Long, lOffset As Long
Dim dScores() As Double
Dim inarray As Variant, NameList As Variant, [B]array_MaxPlayT As Variant[/B]
N = 20
r = 4
lOffset = 7 'Col A --> Col H for scores
lPairs = GetCombinations(r, 2)
If UBound(lPairs) > lOffset Then
MsgBox "You need a bigger offset!"
Exit Sub
End If
NameList = Sheets("CommonData").Range("$E$3:$X$3").Value2 'Places only the Player Numbers into NAMELIST
lCombinations = GetCombinations(N, r)
[B] ReDim array_MaxPlayT(1 To UBound(lCombinations)) As Integer[/B]
ReDim dScores(1 To UBound(lCombinations), 1 To UBound(lPairs))
ReDim arrFreqPlay(1 To UBound(lCombinations), 1 To UBound(lPairs))
ReDim lNumbers(1 To UBound(lCombinations), 1 To r)
inarray = Sheets("CommonData").Range("E5:X24").Value2
arrFreqPlay = Sheets("CommonData2").Range("E6:X25").Value2
For i = 1 To UBound(lCombinations)
For j = 1 To UBound(lPairs)
dScores(i, j) = arrFreqPlay(lCombinations(i, lPairs(j, 1)), lCombinations(i, lPairs(j, 2)))
[B] If Max1 > 0 Then
If dScores(i, j) = Max1 Then
MaxTotal = MaxTotal + 10
End If
End If ' If Max1 > 0
If Max2 < Max1 Then
If dScores(i, j) = Max2 Then
MaxTotal = MaxTotal + 7
End If
End If 'If Max2 < Max1 Then
If Max3 < Max2 Then
If dScores(i, j) = Max3 Then
MaxTotal = MaxTotal + 3
End If
End If 'If Max3 < Max2 Then[/B]
Next j
For j = 1 To r
lNumbers(i, j) = NameList(1, lCombinations(i, j))
Next j
[B] array_MaxPlayT(i) = MaxTotal 'Place cumulative MaxTotal for potential group into array
MaxTotal = 0 'Reset MaxTotal to 0 in prep of examining next set of players[/B]
Next i
With Worksheets(wsName).Range("C7").Resize(UBound(lCombinations)) 'modify sheet name as appropriate
.Resize(, r).Value = lNumbers
[B] .Offset(, lOffset - 1).Resize(, UBound(lPairs)).Value = array_MaxPlayT[/B] 'NOTE: I did IOffset - 1 because I wasn't sure how to modify the existing code to receive this new array
.Offset(, lOffset).Resize(, UBound(lPairs)).Value = dScores
.Offset(, lOffset + UBound(lPairs)).FormulaR1C1 = "=SUM(RC[-" & UBound(lPairs) & "]:RC[-1])"
.Resize(, lOffset + UBound(lPairs) + 1).Sort Key1:=.Columns(lOffset + UBound(lPairs) + 1), Order1:=xlAscending
End With