典型【香川列组合】 的代码和实例:- Dim sj, jg$(), m&, n&, k&
- Sub KagawaCombinArea()
- tms = Timer
- sj = [a1].CurrentRegion
- m = UBound(sj): n = UBound(sj, 2)
-
- k = 1
- For j = 1 To n
- For i = m To 1 Step -1
- If sj(i, j) <> "" Then k = k * i: Exit For
- Next
- Next
- ReDim jg$(k, 1)
- k = 0: Call dgMN("", "", 1)
-
- MsgBox Format(Timer - tms, "0.000s ") & k
-
- If k > Rows.Count Then Exit Sub
- With Cells(1, 1).Offset(m + 5)
- .CurrentRegion = ""
- .Resize(k, 2) = jg
- .Resize(, 2).EntireColumn.AutoFit
- End With
-
- End Sub
- Sub dgMN(r$, s$, j&)
- Dim i&
- For i = 1 To m
- If sj(i, j) <> "" Then
- If j < n Then
- Call dgMN(r & sj(i, j), s & "," & sj(i, j), j + 1)
- Else
- jg(k, 0) = r & sj(i, j)
- jg(k, 1) = Mid(s, 2) & "," & sj(i, j)
- k = k + 1
- End If
- End If
- Next
- End Sub
复制代码 |