7个数字里面选出4个数进行组合(一共35种),用EXCEL罗列出来,怎么做?

2024-10-31 13:29:42
推荐回答(1个)
回答(1):

排列 35 种(组合:将 > 换成 <> 即可):
Sub Combine()
sd = Array(1, 2, 3, 4, 5, 6, 7)
CurrentRow = 1
For a1 = 0 To 6
For a2 = 0 To 6
If a2 > a1 Then
For a3 = 0 To 6
If a3 > a2 And a3 > a1 Then
For a4 = 0 To 6
If a4 > a3 And a4 > a2 And a4 > a1 Then
Cells(CurrentRow, 1) = sd(a1) & sd(a2) & sd(a3) & sd(a4)
CurrentRow = CurrentRow + 1
End If
Next
End If
Next
End If
Next
Next
End Sub