I am trying to generate a total of nPr permutations of words contained in a single column, where 'n' and 'r' are variable. In the example given below, the first column contains the words and second column contains the output.
In this case, n=3 and r=2
Another example, where n=3 and r=3:
So far, I have managed to find a solution in VBA that returns the combinations instead of permutations using below:
Sub Perm()
Dim i As Long, j As Long, last As Long
Count = 2
last = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To last
For j = i + 1 To last
Cells(Count, 2).Value = Cells(i, 1).Value & "," & Cells(j, 1).Value
Count = Count + 1
Next j
Next i
End Sub
With this, I'm able to generate combinations with only n as the variable. r is fixed at 2.



