Minor macro script change

HugoL

New Member
Joined
Jan 25, 2009
Messages
39
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:

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
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
You are more likely to get help, if you explain what you have & what you want to achieve, rather than relying on people to try & reverse engineer your code.
A sample of your data & expected results would also help.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,923
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top