|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Sub test1()
Dim cr, dr, er(), i&, m&, n&
With Intersect([A1].CurrentRegion, Columns("A:E"))
cr = Intersect(.Offset(), .Offset(1)).Value
End With
m = UBound(cr): n = UBound(cr, 2)
ReDim dr(1 To n)
Call cartesianProductDG1(cr, dr, er)
[H1].CurrentRegion.Clear
ReDim cr(1 To UBound(er), 0)
For i = 1 To UBound(er)
cr(i, 0) = er(i)
Next i
With [H1].Resize(UBound(cr))
.Value = cr
.EntireColumn.AutoFit
End With
End Sub
Function cartesianProductDG1(ByVal ar, ByVal br, ByRef vResult, _
Optional ByRef iGroup&, Optional ByVal n& = 1)
Dim i&, j&
For i = 1 To UBound(ar)
If Len(ar(i, n)) Then
br(n) = ar(i, n)
If n = UBound(ar, 2) Then
iGroup = iGroup + 1
ReDim Preserve vResult(1 To iGroup)
vResult(iGroup) = Join(br, "-")
Else
cartesianProductDG1 ar, br, vResult, iGroup, n + 1
End If
End If
Next
End Function
|
评分
-
1
查看全部评分
-
|