你好!Excel 中1-20选任意3个数字排列组合怎样做。 比如1,2,3,或者18,19,20

2024-11-01 23:39:41
推荐回答(1个)
回答(1):

下面程序只算出组合,没有排列
Sub 组合5in20()
Dim I1, I2, I3, I4, I5, M
M = 0

For I1 = 1 To 16
For I2 = I1 + 1 To 17
For I3 = I2 + 1 To 18
For I4 = I3 + 1 To 19
For I5 = I4 + 1 To 20
M = M + 1
Range("A" & M) = I1: Range("B" & M) = I2: Range("C" & M) = I3: Range("D" & M) = I4: Range("E" & M) = I5
Next
Next
Next
Next
Next
End Sub