如何在excel里从1到11任选5个数,然后已5个数一组进行排列组合所有的组合,请高手帮忙。
2个回答
展开全部
在一个空白工作表,按ALT+F11,点右键插入一个模块,输入如下内容,按F5。
Sub Macro1()
Dim Arr1(1 To 5), Arr2(1 To 120, 1 To 5)
Randomize
For i = 1 To 5
Arr1(i) = Int(Rnd * 11 + 1)
Next
a = 1
For i = 1 To 5
For j = 1 To 5
If j = i Then
Else
For k = 1 To 5
If k = i Or k = j Then
Else
For l = 1 To 5
If l = i Or l = k Or l = j Then
Else
For m = 1 To 5
If m = i Or m = j Or m = k Or m = l Then
Else
Arr2(a, 1) = Arr1(i)
Arr2(a, 2) = Arr1(j)
Arr2(a, 3) = Arr1(k)
Arr2(a, 4) = Arr1(l)
Arr2(a, 5) = Arr1(m)
a = a + 1
End If
Next
End If
Next
End If
Next
End If
Next
Next
Range(Cells(1, "A"), Cells(120, "E")) = Arr2
End Sub
Sub Macro1()
Dim Arr1(1 To 5), Arr2(1 To 120, 1 To 5)
Randomize
For i = 1 To 5
Arr1(i) = Int(Rnd * 11 + 1)
Next
a = 1
For i = 1 To 5
For j = 1 To 5
If j = i Then
Else
For k = 1 To 5
If k = i Or k = j Then
Else
For l = 1 To 5
If l = i Or l = k Or l = j Then
Else
For m = 1 To 5
If m = i Or m = j Or m = k Or m = l Then
Else
Arr2(a, 1) = Arr1(i)
Arr2(a, 2) = Arr1(j)
Arr2(a, 3) = Arr1(k)
Arr2(a, 4) = Arr1(l)
Arr2(a, 5) = Arr1(m)
a = a + 1
End If
Next
End If
Next
End If
Next
End If
Next
Next
Range(Cells(1, "A"), Cells(120, "E")) = Arr2
End Sub
更多追问追答
追问
zzxit@163.com 多谢!
追答
已发送到你的邮箱了,你试一试吧,应该没有什么问题。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询