Function UniquePermutes(BaseArray As Variant)
Dim Permuting As Variant
Dim i As Long, j As Long, Pointer As Long
Dim scoreKeeper() As String
Dim tempArray As Variant
If TypeName(BaseArray) = "Range" Then
If BaseArray.Cells.Count = 1 Then
BaseArray = Array(BaseArray.Value)
ElseIf BaseArray.Rows.Count = 1 Then
BaseArray = Application.Transpose(Application.Transpose(BaseArray.Value))
ElseIf BaseArray.Columns.Count = 1 Then
BaseArray = Application.Transpose(BaseArray.Value)
Else
UniquePermutes = CVErr(xlErrValue)
End If
ElseIf Not (BaseArray) Like "*()" Then
UniquePermutes = CVErr(xlErrNum)
End If
Permuting = Permutations(UBound(BaseArray))
ReDim scoreKeeper(1 To UBound(Permuting))
tempArray = BaseArray
For i = 1 To UBound(Permuting)
For j = 1 To UBound(tempArray)
tempArray(j) = BaseArray(Permuting(i)(j))
Next j
If IsError(Application.Match(Join(tempArray), scoreKeeper, 0)) Then
Pointer = Pointer + 1
scoreKeeper(Pointer) = Join(tempArray)
End If
Next i
UniquePermutes = scoreKeeper()
End Function