|
发表于 2017-11-11 16:40
来自手机
|
显示全部楼层
本帖最后由 sikaoge 于 2017-11-11 23:51 编辑
天干5424 发表于 2017-11-6 18:57
求分享一下代码。
我今天回去发给你
Option Base 1
Function supplydate(rang1 As Range, rang2 As Range, Optional header As Boolean = True)
Dim dic1, dic2 As Object
Dim rng1, rng2 As Variant
Dim rng22() As Variant
Set dic1 = CreateObject("Scripting.dictionary")
Set dic2 = CreateObject("Scripting.dictionary")
If header = True Then
rng1 = rang1.Offset(1, 0).Resize(rang1.Rows.Count - 1, rang1.Columns.Count)
rng2 = rang2.Offset(1, 0).Resize(rang2.Rows.Count - 1, rang2.Columns.Count)
Else
rng1 = rang1
rng2 = rang2
End If
ReDim rng22(UBound(rng2))
For j = 1 To UBound(rng2)
For i = 1 To UBound(rng1)
If rng2(j, 1) = rng1(i, 1) Then
dic1(rng1(i, 1)) = dic1(rng1(i, 1)) + rng1(i, 2)
If dic1(rng1(i, 1)) > dic2(rng2(j, 1)) Then
rng22(j) = rng1(i, 3)
Debug.Print dic1(rng1(i, 1))
GoTo 100
End If
End If
Next i
100:
dic2(rng2(j, 1)) = dic2(rng2(j, 1)) + rng2(j, 2)
Debug.Print dic2(rng2(j, 1))
dic1.RemoveAll
Next j
supplydate = WorksheetFunction.Transpose(rng22)
End Function
|
|