如何用EXCEL显示从1到11中任取9个数(数字可重复)的所有排列组合?

2024-12-04 19:37:05
推荐回答(2个)
回答1:

以下为代码及关键注释(请慎用,数据量巨大,电脑一直会在后台计算,如果数据超过65565*250,则会出错)
Sub main()
For i1 = 1 To 9: For i2 = 1 To 9: For i3 = 1 To 9: For i4 = 1 To 9: For i5 = 1 To 9: For i6 = 1 To 9: For i7 = 1 To 9: For i8 = 1 To 9: For i9 = 1 To 9
If i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 < 37 Then'判断条件,9个数之后小于等于36
k = k + 1
Cells(Int((k - 1) / 250) + 1, (k - 1) Mod 250 + 1) = i1 & i2 & i3 & i4 & i5 & i6 & i7 & i8 & i9'实现每行存放250个数据
End If
Next: Next: Next: Next: Next: Next: Next: Next: Next
End Sub

回答2:

所有排列组合?那是天文数字,你实实在在说需要几个?几千个?几十万个?