如何用VBA实现排列组合?
1个回答
展开全部
33个中取任意4个的宏如下:
Sub test()
Dim i, j, k, l As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 30
For j = i + 1 To 31
For k = j + 1 To 32
For l = k + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(0, 2) = k
Selection.Offset(0, 3) = l
Selection.Offset(1, 0).Select
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub
33个中梁谨取任意3个的宏如下:
Sub test()
Dim i, j, k As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 31
For j = i + 1 To 32
For k = j + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(0, 2) = k
Selection.Offset(1, 0).Select
Next
Next
Next
Application.ScreenUpdating = True
End Sub
33个中取任意亩渣猛迅桥2个的宏如下:
Sub test()
Dim i, j As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 32
For j = i + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(1, 0).Select
Next
Next
Application.ScreenUpdating = True
End Sub
在2007版中,还可以实现取5个的,自己对照修改吧。取6个以上,格子不够。
Sub test()
Dim i, j, k, l As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 30
For j = i + 1 To 31
For k = j + 1 To 32
For l = k + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(0, 2) = k
Selection.Offset(0, 3) = l
Selection.Offset(1, 0).Select
Next
Next
Next
Next
Application.ScreenUpdating = True
End Sub
33个中梁谨取任意3个的宏如下:
Sub test()
Dim i, j, k As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 31
For j = i + 1 To 32
For k = j + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(0, 2) = k
Selection.Offset(1, 0).Select
Next
Next
Next
Application.ScreenUpdating = True
End Sub
33个中取任意亩渣猛迅桥2个的宏如下:
Sub test()
Dim i, j As Byte
Application.ScreenUpdating = False
Cells(1, 1).Select
For i = 1 To 32
For j = i + 1 To 33
Selection = i
Selection.Offset(0, 1) = j
Selection.Offset(1, 0).Select
Next
Next
Application.ScreenUpdating = True
End Sub
在2007版中,还可以实现取5个的,自己对照修改吧。取6个以上,格子不够。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询