我有一组数字,1-33。我需要一种快速的方法来生成这些数字中的三个的每个排列,从而导致升序。
示例:
7 19 25
1 2 3
10 20 30
但不是:
7 5 9
11 23 22
有没有办法在Excel中执行此操作?
由于
答案 0 :(得分:2)
这将生成从1到33
的所有5456个整数组合Sub ListUm()
Dim i As Long, j As Long, k As Long, Z As Long
Z = 1
For i = 1 To 31
For j = i + 1 To 32
For k = j + 1 To 33
Cells(Z, 1) = i & "," & j & "," & k
Z = Z + 1
Next k
Next j
Next i
End Sub
由于您有指定的订单,因此您可以使用组合而不是排列。
答案 1 :(得分:1)
或许这样的事情?
Sub Testing123()
Dim seedMax As Integer
Dim a As Integer
Dim b As Integer
Dim c As Integer
seedMax = 33
For a = 1 To seedMax
For b = a + 1 To seedMax
For c = b + 1 To seedMax
Debug.Print a, b, c
Next c
Next b
Next a
End Sub
将其写入工作表:
Sub Testing123withSheetWrite()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim seedMax As Integer: seedMax = 33
Dim x As Long: x = 1
Dim y As Long: y = 1
For a = 1 To seedMax
For b = a + 1 To seedMax
For c = b + 1 To seedMax
Debug.Print a, b, c
Cells(x, y + 0) = a
Cells(x, y + 1) = b
Cells(x, y + 2) = c
x = x + 1
Next c
Next b
Next a
End Sub
答案 2 :(得分:0)