请教一下,用excel中的VBA如何实现排列组合的操作?
用1-12这12个数字,从中选取6个数字做无顺序的组合数据,即一共为C(12,6)=924组数据,一组数据显示一行,如,第一组数据为“123456”,第二组数据在第二行中...
用1-12这12个数字,从中选取6个数字做无顺序的组合数据,即一共为C(12,6)=924组数据,一组数据显示一行,如,第一组数据为“1 2 3 4 5 6”,第二组数据在第二行中显示“1 2 3 4 5 7”,用excel该如何操作呢?请各位朋友帮帮忙,很急,谢谢!
要求每组数据的六个数字从“A1”排列到“F1”格,即一个数字一个格。麻烦大家了。 展开
要求每组数据的六个数字从“A1”排列到“F1”格,即一个数字一个格。麻烦大家了。 展开
展开全部
楼上的需要稍作改动如下即能满足要求:
Sub Click()
Dim a, b, c, d, e, f, i
i = 1
For a = 1 To 12
For b = a + 1 To 12
For c = b + 1 To 12
For d = c + 1 To 12
For e = d + 1 To 12
For f = e + 1 To 12
Cells(i, 1) = a
Cells(i, 2) = b
Cells(i, 3) = c
Cells(i, 4) = d
Cells(i, 5) = e
Cells(i, 6) = f
i = i + 1
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
Sub Click()
Dim a, b, c, d, e, f, i
i = 1
For a = 1 To 12
For b = a + 1 To 12
For c = b + 1 To 12
For d = c + 1 To 12
For e = d + 1 To 12
For f = e + 1 To 12
Cells(i, 1) = a
Cells(i, 2) = b
Cells(i, 3) = c
Cells(i, 4) = d
Cells(i, 5) = e
Cells(i, 6) = f
i = i + 1
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Sub Click()
Dim a%, b%, c%, d%, e%, f%, i%
For a = 1 To 12
For b = a + 1 To 12
For c = b + 1 To 12
For d = c + 1 To 12
For e = d + 1 To 12
For f = e + 1 To 12
i = i + 1
Cells(i, 1) = a & "," & b & "," & c & "," & d & "," & e & "," & f
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
Dim a%, b%, c%, d%, e%, f%, i%
For a = 1 To 12
For b = a + 1 To 12
For c = b + 1 To 12
For d = c + 1 To 12
For e = d + 1 To 12
For f = e + 1 To 12
i = i + 1
Cells(i, 1) = a & "," & b & "," & c & "," & d & "," & e & "," & f
Next f
Next e
Next d
Next c
Next b
Next a
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己去录制宏代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询