提示:其它语言是由 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。 支持所有语言。 在您的企业或组织中轻松部署。 全功能60天免费试用。
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 · 2 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 · 4 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 · 4 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 · 4 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 · 1 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 · 1 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.