Sub excelNewbie22()
'
Dim InputNumbersRow As Long
Dim LastRow As Long, StartRow As Long
Dim SourceArray() As Long, OutputArray(1 To 6, 1 To 5) As Long
Dim OutputRow As Long
Dim SourceArrayColumn As Long, SourceArrayRow As Long
Dim OutputColumn As String
Dim InputNumbersArray As Variant
'
StartRow = 2 ' <--- Set this to the starting row of numbers to use
OutputColumn = "G" ' <--- Set this to the Column letter to display results to
LastRow = Range("A" & Rows.Count).End(xlUp).Row ' Get last row # of numbers to use
SourceArray = GetCombinations(6, 5) ' Load SourceArray with all non repeating 5 out of 6 combinations
'
For InputNumbersRow = StartRow To LastRow Step 7 '
OutputRow = InputNumbersRow + 1 ' Set the OutputRow
'
InputNumbersArray = Range("A" & InputNumbersRow).Resize(1, 6) ' Save numbers to use to InputNumbersArray
'
For SourceArrayRow = 1 To 6 ' Loop through rows of the SourceArray
For SourceArrayColumn = 1 To 5 ' Loop through columns of the SourceArray
If SourceArray(SourceArrayRow, SourceArrayColumn) = 1 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 1) ' Perform replacement array values ...
ElseIf SourceArray(SourceArrayRow, SourceArrayColumn) = 2 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 2)
ElseIf SourceArray(SourceArrayRow, SourceArrayColumn) = 3 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 3)
ElseIf SourceArray(SourceArrayRow, SourceArrayColumn) = 4 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 4)
ElseIf SourceArray(SourceArrayRow, SourceArrayColumn) = 5 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 5)
ElseIf SourceArray(SourceArrayRow, SourceArrayColumn) = 6 Then
OutputArray(SourceArrayRow, SourceArrayColumn) = InputNumbersArray(1, 6)
End If
Next ' Loop back
Next ' Loop back
'
Range(OutputColumn & OutputRow).Resize(UBound(OutputArray), 5).Value = OutputArray ' Display results to sheet
Next ' Loop back
End Sub
Function GetCombinations(lNumber As Long, lNoChosen As Long) As Long()
Dim lOutput() As Long, lCombinations As Long
Dim i As Long, j As Long, k As Long
lCombinations = WorksheetFunction.Combin(lNumber, lNoChosen)
ReDim lOutput(1 To lCombinations, 1 To lNoChosen)
For i = 1 To lNoChosen
lOutput(1, i) = i
Next i
For i = 2 To lCombinations
For j = 1 To lNoChosen
lOutput(i, j) = lOutput(i - 1, j)
Next j
For j = lNoChosen To 1 Step -1
lOutput(i, j) = lOutput(i, j) + 1
If lOutput(i, j) <= lNumber - (lNoChosen - j) Then Exit For
Next j
For k = j + 1 To lNoChosen
lOutput(i, k) = lOutput(i, k - 1) + 1
Next k
Next i
GetCombinations = lOutput
End Function