求问!在EXCEL中从1~35个数字选5个全排,把结果全列出来的公式。
从A1-AI1中填充数列 1 2 3 4 5 …… 35然后使用如下宏代码:Sub test()
Dim i, j, k, l, m, n As Byte
Dim x As Long, y As Long
Application.ScreenUpdating = False
Range("A2:E65536").ClearContents
x = 2
y = 1
For i = 1 To 35 - 4
For j = i + 1 To 35 - 3
For k = j + 1 To 35 - 2
For l = k + 1 To 35 - 1
For m = l + 1 To 35
Cells(x, y) = Cells(1, i)
Cells(x, y + 1) = Cells(1, j)
Cells(x, y + 2) = Cells(1, k)
Cells(x, y + 3) = Cells(1, l)
Cells(x, y + 4) = Cells(1, m)
x = x + 1
If x > 65536 Then
x = 2
y = y + 6
End If
Next
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub
运行结果共有:324632 组
扩展资料:
如数据在A1:E15,为了排列时显得整齐,我用A,B,C,D,E,F代替了10,11,12,13,14,15
在F1中输入公式:=OFFSET($A$1,0+(ROW()-1)/(COUNTA(B:B)*COUNTA(C:C)*COUNTA(D:D)*COUNTA(E:E)),0,,) ,下拉。
在G1中输入公式:=OFFSET($A$1,MOD((ROW()-1)/(COUNTA(C:C)*COUNTA(D:D)*COUNTA(E:E)),COUNTA(B:B)),1,,) ,下拉。
在H1中输入公式:=OFFSET($A$1,MOD((ROW()-1)/(COUNTA(D:D)*COUNTA(E:E)),COUNTA(C:C)),2,,) ,下拉。
在I1中输入公式:=OFFSET($A$1,MOD((ROW()-1)/COUNTA(E:E),COUNTA(D:D)),3,,) ,下拉。
在J1中输入公式:=OFFSET($A$1,MOD((ROW()-1),COUNTA(E:E)),4,,) ,下拉。
在K1中输入公式:=F1&G1&H1&I1&J1,下拉。
推荐于2019-07-09
Dim i, j, k, l, m, n As Byte
Dim x As Long, y As Long
Application.ScreenUpdating = False
Range("A2:E65536").ClearContents
x = 2
y = 1
For i = 1 To 35 - 4
For j = i + 1 To 35 - 3
For k = j + 1 To 35 - 2
For l = k + 1 To 35 - 1
For m = l + 1 To 35
Cells(x, y) = Cells(1, i)
Cells(x, y + 1) = Cells(1, j)
Cells(x, y + 2) = Cells(1, k)
Cells(x, y + 3) = Cells(1, l)
Cells(x, y + 4) = Cells(1, m)
x = x + 1
If x > 65536 Then
x = 2
y = y + 6
End If
Next
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub
运行结果共有:324632 组
2013-06-28
2013-06-28