## How to generate or list all possible permutations in Excel?

For example, I have three characters XYZ, now, I want to list all possible permutations based on these three characters to get six different results as this: XYZ, XZY, YXZ, YZX, ZXY and ZYX. In Excel, how could you quickly generate or list all permutations based on different number of characters?

**Generate or list all possible permutations based on characters with VBA code**

#### ** Generate or list all possible permutations based on characters with VBA code**

The following VBA code may help you to list all permutations based on your specific number of letters please do as follows:

**1**. Hold down the** ALT + F11** keys to open the **Microsoft Visual Basic for Applications** window.

**2**. Click **Insert** > **Module**, and paste the following code in the **Module** Window.

**VBA code: List all possible permutations in excel**

Sub GetString()
'Updateby Extendoffice
Dim xStr As String
Dim FRow As Long
Dim xScreen As Boolean
xScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
xStr = Application.InputBox("Enter text to permute:", "Kutools for Excel", , , , , , 2)
If Len(xStr) < 2 Then Exit Sub
If Len(xStr) >= 8 Then
MsgBox "Too many permutations!", vbInformation, "Kutools for Excel"
Exit Sub
Else
ActiveSheet.Columns(1).Clear
FRow = 1
Call GetPermutation("", xStr, FRow)
End If
Application.ScreenUpdating = xScreen
End Sub
Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long)
Dim i As Integer, xLen As Integer
xLen = Len(Str2)
If xLen < 2 Then
Range("A" & xRow) = Str1 & Str2
xRow = xRow + 1
Else
For i = 1 To xLen
Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow)
Next
End If
End Sub

**3**. Then press **F5** key to run this code, and a prompt box is popped out to remind you enter the characters that you want to list all permutations, see screenshot:

**4**. After entering the characters, and then click **OK** button, all the possible permutations are displayed in column A of active worksheet. See screenshot:

**Note**: If the entered character length is equal or greater than 8 characters, this code will not work because there are too many permutations.

**List or generate all possible combinations from multiple columns**

If you need to generate all possible combinations based on multiple columns data, maybe, there is not a good way for dealing with the task. But, **Kutools for Excel**'s **List All Combinations** utility can help you to list all possible combinations quickly and easily.** Click to download Kutools for Excel!**

**Kutools for Excel**: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.** Download and free trial Now! **

### The Best Office Productivity Tools

#### Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

**Reuse**: Quickly insert **complex formulas, charts** and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails... - Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
- Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
- Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
- Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
- Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
- Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
- Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
- More than 300 powerful features. Supports Office/Excel
2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features
30-day free trial. 60-day money back guarantee.

#### Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

**Enable tabbed editing and reading in Word, Excel, PowerPoint**, Publisher, Access, Visio and Project. - Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!