|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub test()
Dim d As Object
Dim i%, j%, lr%, mysum%
Dim arr, brr
Dim s1, s2
Dim sh As Worksheet, sht As Worksheet
Application.ScreenUpdating = False: Application.DisplayAlerts = False
Set sh = Worksheets("订单模板"): Set sht = Worksheets("活动时间1")
lr = sh.Cells(Rows.Count, 2).End(3).Row
arr = sh.Range("B2:S" & lr): brr = sht.[a1].CurrentRegion
If arr(1, 4) < brr(1, 2) Or arr(1, 4) > brr(1, 4) Then
Exit Sub
End If
Set d = CreateObject("scripting.dictionary")
For i = 3 To UBound(brr)
s = brr(i, 1) & brr(i, 2)
If Not d.exists(s) Then
d(s) = Array(brr(i, 5), brr(i, 6), brr(i, 7))
End If
Next
For i = 7 To UBound(arr)
s1 = arr(1, 15) & arr(i, 1)
mysum = arr(i, 9)
For j = i + 1 To UBound(arr)
s2 = arr(1, 15) & arr(j, 1)
If d(s1)(2) = d(s2)(2) Then
mysum = mysum + arr(j, 8)
Else
Exit For
End If
Next
If mysum >= d(s1)(0) Then
For m = i To j - 1
arr(m, 17) = d(s1)(1)
Next
End If
Next
sh.[b2].Resize(UBound(arr), UBound(arr, 2)) = arr
Set d = Nothing
Application.ScreenUpdating = True: Application.DisplayAlerts = True
MsgBox "完成"
End Sub
|
评分
-
1
查看全部评分
-
|