用VBA从不同组数选出2个数组合成一个不重复的5个数的排列组

1个回答

  • VBA代码如下,不包含第四行的你自己稍加修改一下。Sub Combine()

    Dim myArr1(1 To 5)

    Dim myArr2(1 To 5)

    Dim myArr3(1 To 5)

    Dim myArr4(1 To 5)

    Dim i As Single

    Dim myRow As Single

    myRow = 1

    For i = 1 To 5 '定义赋值四组数据

    myArr1(i) = Split("1 2 3 4 5", Space(1))(i - 1)

    myArr2(i) = Split("4 5 6 7 8", Space(1))(i - 1)

    myArr3(i) = Split("4 5 3 2 9", Space(1))(i - 1)

    myArr4(i) = Split("2 6 8 9 1", Space(1))(i - 1)

    Next

    Dim Flag As Single

    Flag = 0

    Dim N1_1, N1_2, N2, N3_1, N3_2 As Single

    For N1_1 = 1 To 4

    For N1_2 = 1 To 4

    For N2 = 1 To 4

    For N3_1 = 1 To 4

    For N3_2 = 1 To 4

    If N1_1 = N1_2 Or N3_1 = N3_2 Then Flag = 1

    If Flag = 0 Then

    Cells(myRow, 1) = myArr1(N1_1) Space(1) myArr1(N1_2) Space(1) _

    myArr2(N2) Space(1) myArr3(N3_1) Space(1) myArr1(N3_2) Space(1)

    myRow = myRow + 1

    End If

    Flag = 0

    Next

    Next

    Next

    Next

    Next

    End Su