EXCEL如何列出1-12每8个数一组
发布网友
发布时间:2023-08-17 18:41
我来回答
共2个回答
热心网友
时间:2024-12-04 05:43
可以使用VBA代码对其进行穷举。
实际组合排列数量为19958400,而最新版本excel每列也不过1048576行,能够填满19列。
如下回答参考了moonstarless的回答(750285508229702132)
1、复制如下代码到代码栏中;
2、F5运行(需要几分钟);
3、回到sheet中查看结果。
Sub Arr()
Dim i, j, k, l, m, n, o, p As Long
Dim a, b, c, d, e, f, g, h As String
Dim myRow As Single
myRow = 1
Set mysheet1 = ThisWorkbook.Worksheets("Sheet1")
For i = 1 To 12
For j = 1 To 12
For k = 1 To 12
For l = 1 To 12
For m = 1 To 12
For n = 1 To 12
For o = 1 To 12
For p = 1 To 12
a = Choose(i, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If j <> i Then
b = Choose(j, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If k <> i And k <> j Then
c = Choose(k, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If l <> i And l <> j And l <> k Then
d = Choose(l, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If m <> i And m <> j And m <> k And m <> l Then
e = Choose(m, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If n <> i And n <> j And n <> k And n <> l And n <> m Then
f = Choose(n, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If o <> i And o <> j And o <> k And o <> l And o <> m And o <> n Then
g = Choose(o, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
If p <> i And p <> j And p <> k And p <> l And p <> m And p <> n And p <> o Then
h = Choose(p, "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")
myRow = myRow + 1
mysheet1.Cells(myRow Mod 1048576 + 1, Len(myRow / 1048576)) = a & b & c & d & e & f & g & h
End If
End If
End If
End If
End If
End If
End If
Next
Next
Next
Next
Next
Next
Next
Next
End Sub
热心网友
时间:2024-12-04 05:43
这个我写过,需要用代码来组合!