提示:其他語言是Google翻譯的。 你可以訪問 English 版本。
登入
x
or
x
x
註冊
x

or

如何生成或列出所有可能的排列在Excel中?

例如,我有三個字符XYZ,現在我想根據這三個字符列出所有可能的排列,以得到六個不同的結果,如下所示:XYZ,XZY,YXZ,YZX,ZXY和ZYX。 在Excel中,您如何快速生成或列出基於不同字符數的所有排列?

用VBA代碼生成或列出所有可能的基於字符的排列


列出或生成多列的所有可能組合

如果您需要基於多列數據生成所有可能的組合,可能,沒有一種好的方法來處理任務。 但, Kutools for Excel's 列出所有組合 實用程序可以幫助您快速輕鬆地列出所有可能的組合。 點擊下載Kutools for Excel!

doc列出所有組合

Kutools for Excel:比300方便的Excel加載項,可以在60天免費試用。 下載並免費試用現在!


箭頭藍色右泡 用VBA代碼生成或列出所有可能的基於字符的排列


以下VBA代碼可能會幫助您根據您的特定信件數量列出所有排列,請按照以下方式進行操作:

1。 按住 ALT + F11 鍵打開 Microsoft Visual Basic for Applications 窗口。

2。 點擊 插入 > 模塊,並將以下代碼粘貼到 模塊 窗口。

VBA代碼:在Excel中列出所有可能的排列

Sub GetString()
'Updateby Extendoffice 20160606
    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。 然後按 F5 鍵來運行此代碼,並彈出提示框提醒您輸入要列出所有排列的字符,請參閱截圖:

doc列表排列1

4。 輸入字符後,再單擊 OK 按鈕,所有可能的排列都顯示在活動工作表的A列中。 看截圖:

doc列表排列2

備註:如果輸入的字符長度等於或大於8個字符,則此代碼將無效,因為排列過多。

doc列表排列3


Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及你以前用過的任何東西; 加密單元格 密碼; 創建郵件列表 並發送電子郵件...
  • 超級方程式酒吧 (輕鬆編輯多行文字和公式); 閱讀佈局 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不丟失數據; 分裂細胞含量; 組合重複的行/列...防止重複的細胞; 比較範圍...
  • 選擇複製或唯一 行; 選擇空行 (所有細胞都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇......
  • 精確複製 多個單元格而不更改公式參考; 自動創建參考 多張表; 插入項目符號,複選框等等......
  • 提取文本,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級過濾器 (將過濾方案保存並應用到其他工作表); 高級排序 按月/週/日,頻率等; 特殊過濾器 用粗體,斜體......
  • 結合工作簿和工作表; 根據鍵列合併表; 將數據拆分為多個表格; 批量轉換xls,xlsx和PDF...
  • 超過300強大的功能。 支持Office / Excel 2007-2019和365。 支持所有語言。 在您的企業或組織中輕鬆部署。 全功能30天免費試用。
kte tab 201905

Office選項卡為Office提供選項卡式界面,使您的工作更輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,Publisher,Access,Visio和Project。
  • 在同一窗口的新選項卡中打開並創建多個文檔,而不是在新窗口中。
  • 通過50%提高您的工作效率,每天為您減少數百次鼠標點擊!
官方底部
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    lyto · 5 months ago
    who can send me a list of 10 diferent items permutatted by 2 outcomes. this code doe

    snt work on this
  • To post as a guest, your comment is unpublished.
    ilhan · 6 months ago
    peki bunu listeleyecek bir program uygulama yok mu?basit sıradan bir hesaplamadan daha fazlasına ihtiyacı olan ne yapacak?
  • To post as a guest, your comment is unpublished.
    MC · 7 months ago
    this code will not work because there are two many permutations


    should be:

    this code will not work because there are too many permutations


    HTH
    • To post as a guest, your comment is unpublished.
      skyyang · 7 months ago
      Hello, MC,
      Thank you for your warm reminder, it is my mistake. I have corrected it.
      Thanks a lot!
  • To post as a guest, your comment is unpublished.
    Paul · 1 years ago
    Hello everyone. I need help on this. I have two alphabets to be permutated in 20 rows. But am not getting it right. Anyone who could help me out should send the permutation to my email. pauladah69@gmail.com.


    1.a b b a
    2.a a b b
    3.a a b b
    4.a a b b
    5.a a b b
    6.a a b b
    7.a a b b
    8.a a b b
    9.a a b b
    10.a a b b
    11.a a b b
    12.a a b b
    13.a a b b
    14.a a b b
    15.a a b b
    16.a a b b
    17.a a b b
    18.a a b b
    19.a a b b
    20.a a b b
  • To post as a guest, your comment is unpublished.
    Wule · 1 years ago
    How many sequences of 3things can be formed from 7 different things replacement and order is important?
  • To post as a guest, your comment is unpublished.
    Declan Keogh · 2 years ago
    @Supraja...

    in the first sub clear all cells... not just the first row
    --Cells.Clear

    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
    'move to the next column when you get to 100
    Cells(((xRow - 1) Mod 100) + 1, 1 + Int(xRow / 100)) = 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
  • To post as a guest, your comment is unpublished.
    Supraja · 2 years ago
    Hello,

    Im trying to get a permutation for 82 characters, the code provided works, but, since the columns are only 1048576, I want to move the next output in B,C,D..... Can any of you help me on this regard
  • To post as a guest, your comment is unpublished.
    Terence · 2 years ago
    Hello,

    Im doing a small project using permutation and combination rules. I need your support on this please.
    Scenario: I have 13 digit alpha numeric data (00SHGO8BJIDG0) I want a coding to interchange S to 5, I to 1 and O to 0 and vise versa.

    The project is that if I have the correct 13 digit data I will receive a 3 digit pass code.

    (eg) 00SHG08BJ1DG0 - 500 is the pass code but because of wrong typo that is instead of 1 it was I and 0 it was O there is a wrong info.
    can you please help me.