【问题标题】:Using excel find all possible combinations [duplicate]使用excel查找所有可能的组合[重复]
【发布时间】:2018-02-25 15:18:16
【问题描述】:

有没有办法在 excel 中找出所有可能的表格组合,但每列可以取 2 或 3 个值。 ?

假设这是我需要排序的:

A             A | B | C | D |
1             1 | 1 | 1 | 1 |
2             1 | 1 | 1 | 2 |
3             1 | 1 | 2 | 1 |
              1 | 2 | 1 | 1 |
              2 | 1 | 1 | 1 |
              ..............
              ...............
B 
1
2

C
1
2

D
1
2
3

【问题讨论】:

  • 需要更多信息 - 例如,左侧栏中的 '3' 来自哪里?
  • Hi lee,..... 代表表格的延续... 2|2|2|2 等等。 3 将出现 3|1|1|1 、 3|1|1|2 等等。我正在尝试创建/查找可以填充该表的所有矩阵的脚本。

标签: excel vba


【解决方案1】:

也许你正在追求这个(未经测试,但它至少应该给你一个想法)

Sub Combinations
    Dim i As Long, j As Long, k As Long, l As Long
    Dim iRow As Long
    For i = 1 To 3 ‘ change 3 to your first column actual last number
        For j = 1 To 2‘ change 2 to your second column avtual last number
            For k = 1 To 3 ‘ change 3 to your third column actual last number
                For l = 1 To 4 ‘ change 4 to your fourth column actual last number
                    iRow = iRow + 1
                    Cells(iRow,1).Resize(,4).Value = Array(i,j,k,l)
                Next
            Next
        Next
     Next
End Sub

【讨论】:

    猜你喜欢
    • 2019-06-04
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多