|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
我写了排列组合的代码,请大师指点下 A列是数据 b1是要排列组合的数据
Dim x As Long '总行数
Dim dicdata, colldata
Dim m As Integer
Dim row_arr, col_arr, indata
Sub a()
ReDim indata(1 To [a1].End(xlDown).Row)
Dim n As Integer
Set colldata = New Collection
Set dicdata = CreateObject("Scripting.Dictionary")
For n = 1 To [a1].End(xlDown).Row
colldata.Add "-" & Cells(n, 1)
indata(n) = Range("A" & n)
Next
End Sub
Function h1(str)
Dim n As Integer
n = Len(str) - Len(Application.WorksheetFunction.Substitute(str, "-", ""))
h1 = n
End Function
Function laststr(str)
Dim STR1 As String
Dim n As Integer, k&
n = Len(str) - Len(Application.WorksheetFunction.Substitute(str, "-", ""))
STR1 = Application.WorksheetFunction.Substitute(str, "-", "#", n)
k = Application.WorksheetFunction.Find("#", STR1, 1)
STR1 = Right(str, Len(str) - k)
For n = 1 To [a1].End(xlDown).Row
If STR1 = indata(n) Then laststr = n
Next
End Function
Sub okk()
m = Cells(1, 2)
Call a
Dim n1&, n2&, n3&
Do
If h1(colldata(1)) = m Then
Exit Do
ElseIf h1(colldata(1)) < m Then
For n1 = laststr(colldata(1)) + 1 To [a1].End(xlDown).Row
colldata.Add colldata(1) & "-" & indata(n1)
Next
End If
colldata.Remove 1
Loop
For n3 = 1 To colldata.Count
Range("D" & n3) = colldata(n3)
Next
End Sub
|
|