|
'目测了一下应该差不多,,,
Option Explicit
Sub test()
Dim arr, i, j, m, n, s, t, dic(2)
For i = 0 To UBound(dic)
Set dic(i) = CreateObject("scripting.dictionary")
Next
arr = Range("a3:c" & Cells(Rows.Count, "b").End(xlUp).Row).Value
For i = 1 To UBound(arr, 1)
dic(0)(arr(i, 1)) = dic(0)(arr(i, 1)) & Space(1) & arr(i, 2)
dic(1)(arr(i, 2)) = arr(i, 3)
Next
s = [f1].Value: n = [h1].Value
If Not dic(0).exists(s) Then MsgBox s: Exit Sub
ReDim arr(1 To UBound(arr, 1), 1 To 3)
t = Split(dic(0)(s))
Do
For i = 1 To UBound(t)
m = m + 1
arr(m, 1) = t(i)
arr(m, 2) = dic(1)(t(i))
If dic(0).exists(t(i)) Then
s = Split(dic(0)(t(i)))
For j = 1 To UBound(s)
dic(2)("a") = dic(2)("a") & Space(1) & s(j)
dic(1)(s(j)) = dic(1)(s(j)) * arr(m, 2)
Next
End If
Next
If dic(2).Count > 0 Then t = Split(dic(2)("a")): dic(2).RemoveAll Else Exit Do
Loop
For i = 1 To m
arr(i, 3) = arr(i, 2) * n
Next
[e3].Resize(UBound(arr, 1), UBound(arr, 2)) = arr
End Sub |
评分
-
4
查看全部评分
-
|