Option Explicit Function combinant(arr, str, cnt, m, n, s) Dim i As Integer If n = 0 Then cnt = cnt + 1: arr(cnt, 1) = s Else For i = m To Len(str): combinant arr, str, cnt, i + 1, n - 1, s & Mid(str, i, 1): Next End If End Function Sub test() Dim i, j, arr, str, cnt arr = Range("a1:c" & [a65536].End(xlUp).Row) For i = 1 To UBound(arr, 1) For j = 1 To UBound(arr, 2) str = str & arr(i, j) Next j, i i = UBound(arr, 1) * UBound(arr, 2) ReDim arr(1 To i * (i - 1) * (i - 2) / 6, 1 To 1) combinant arr, str, cnt, 1, 3, "" [d:d].ClearContents If cnt > 0 Then [d1].Resize(UBound(arr, 1), 1) = arr End Sub
Option Explicit Sub test() Dim a, b, c, d, n, arr(1 To 16 ^ 4, 1 To 1) For a = 1 To [a65536].End(xlUp).Row For b = 1 To [b65536].End(xlUp).Row For c = 1 To [c65536].End(xlUp).Row For d = 1 To [d65536].End(xlUp).Row n = n + 1 arr(n, 1) = Cells(a, 1) & Cells(b, 2) & Cells(c, 3) & Cells(d, 4) Next d, c, b, a [e:e].ClearContents [e1].Resize(n, 1) = arr End Sub