香川群子 发表于 2012-11-14 11:00
这个问题用VBA数组循环,好像还难以简明解决。 - Dim arr, brr(1 To 3 ^ 5 * 4), crr
- Dim a%, b%, c%, d%, e%, f%, x$, s&, s2&, y
- arr = Range("a1").CurrentRegion
- For a = 1 To 3
- For b = 1 To 3
- For c = 1 To 3
- For d = 1 To 3
- x = arr(a, 1) & "," & arr(b, 2) & "," & arr(c, 3) & "," & arr(d, 4)
- For e = 1 To 3
- For f = 1 To 4
- If InStr("," & x & ",", "," & arr(e, f) & ",") = 0 Then
- s = s + 1
- brr(s) = x & "," & arr(e, f)
- End If
- Next f, e, d, c, b, a
- ReDim crr(1 To s, 1 To 5)
- For i = 1 To s
- x = "," & brr(i) & ","
- For j = i + 1 To s
- y = Split(brr(j), ",")
- For k = 0 To UBound(y)
- x = Replace(x, "," & y(k) & ",", ",")
- Next
- If x = "," Then brr(j) = ""
- x = "," & brr(i) & ","
- Next
- Next
- For i = 1 To s
- If brr(i) <> "" Then
- s2 = s2 + 1
- z = Split(brr(i), ",")
- For j = 0 To UBound(z)
- crr(s2, j + 1) = z(j)
- Next
- End If
- Next
- Range("f1").Resize(s2, 5) = crr
复制代码 |