Hi,
Could someone help me to convert this code as follows?
Write the permutation of the items listed in column 'A' to separate columns.
I would like to use it as shown in the example.
Sample:
<tbody>
</tbody>
Code:
Option Explicit
Option Compare Text
Dim CurrentRow
Sub DoString()
On Error Resume Next
Dim Instring As String
Dim i As Integer, j As Integer
Instring = Range("A1").Value
Range("A1").Select
CurrentRow = 1
Call GetPermutation("", Instring)
TxToCoL
End Sub
Sub GetPermutation(X As String, y As String)
On Error Resume Next
Dim j, i
j = Len
If j < 2 Then
Cells(CurrentRow, 1) = X & y
CurrentRow = CurrentRow + 1
Else
For i = 1 To j
Call GetPermutation(X + Mid(y, i, 1), _
Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub
Sub TxToCoL()
'Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Select
Range("A1:A40320").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array _
(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1)), _
TrailingMinusNumbers:=True
End Sub
Could someone help me to convert this code as follows?
Write the permutation of the items listed in column 'A' to separate columns.
I would like to use it as shown in the example.
Sample:
Items | Result | |||||
1 | 1 | 2 | 3 | A | ||
2 | 1 | 2 | A | 3 | ||
3 | 1 | 3 | 2 | A | ||
A | 1 | 3 | A | 2 | ||
1 | A | 2 | 3 | |||
1 | A | 3 | 2 | |||
2 | 1 | 3 | A | |||
2 | 1 | A | 3 | |||
2 | 3 | 1 | A | |||
2 | 3 | A | 1 | |||
2 | A | 1 | 3 | |||
2 | A | 3 | 1 | |||
3 | 1 | 2 | A | |||
3 | 1 | A | 2 | |||
3 | 2 | 1 | A | |||
3 | 2 | A | 1 | |||
3 | A | 1 | 2 | |||
3 | A | 2 | 1 | |||
A | 1 | 2 | 3 | |||
A | 1 | 3 | 2 | |||
A | 2 | 1 | 3 | |||
A | 2 | 3 | 1 | |||
A | 3 | 1 | 2 | |||
A | 3 | 2 | 1 |
<tbody>
</tbody>
Code:
Option Explicit
Option Compare Text
Dim CurrentRow
Sub DoString()
On Error Resume Next
Dim Instring As String
Dim i As Integer, j As Integer
Instring = Range("A1").Value
Range("A1").Select
CurrentRow = 1
Call GetPermutation("", Instring)
TxToCoL
End Sub
Sub GetPermutation(X As String, y As String)
On Error Resume Next
Dim j, i
j = Len
If j < 2 Then
Cells(CurrentRow, 1) = X & y
CurrentRow = CurrentRow + 1
Else
For i = 1 To j
Call GetPermutation(X + Mid(y, i, 1), _
Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub
Sub TxToCoL()
'Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row).Select
Range("A1:A40320").Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array _
(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1)), _
TrailingMinusNumbers:=True
End Sub