Hello all,
I'm requesting some help to make some minor adjustement to an existing macro script. Essentially, i want the script to limit the output generated to 3 words and to add ''1'' at the end of the words. Thank you.
Here is the existing script:
I'm requesting some help to make some minor adjustement to an existing macro script. Essentially, i want the script to limit the output generated to 3 words and to add ''1'' at the end of the words. Thank you.
Here is the existing script:
VBA Code:
Option Explicit
Sub PermutationsN()
Dim vElements As Variant, vresult As Variant
Dim lRow As Long, i As Long
vElements = Application.Transpose(Range("A1", Range("A1").End(xlDown)))
Columns("B:Z").Clear
For i = 1 To UBound(vElements)
ReDim vresult(1 To i)
Call PermutationsNPR(vElements, i, vresult, lRow, 1)
Next i
End Sub
Sub PermutationsNPR(vElements As Variant, p As Long, vresult As Variant, lRow As Long, iIndex As Integer)
Dim i As Long, unique As Variant
For i = 1 To UBound(vElements)
vresult(iIndex) = vElements(i)
If iIndex = p Then
unique = UniqueArray(vresult)
If (UBound(vresult) = UBound(unique)) Then
lRow = lRow + 1
Cells(lRow, 3).Value = Join(unique)
End If
Else
Call PermutationsNPR(vElements, p, vresult, lRow, iIndex + 1)
End If
Next i
End Sub
Function UniqueArray(todoarray As Variant) As Variant
Dim arr As New Collection, a
Dim i As Long
On Error Resume Next
For Each a In todoarray
arr.Add a, a
Next
ReDim returnVal(1 To arr.count)
For i = 1 To arr.count
returnVal(i) = arr(i)
Next
UniqueArray = returnVal
End Function