|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub ykcbf20240331()
Set d = CreateObject("scripting.dictionary")
str1 = [m2].Value
If Len(str1) = 0 Then
MsgBox "订单号不能为空"
Exit Sub
End If
arr = Sheets("订单明细").UsedRange
ReDim brr(1 To UBound(arr), 1 To 8)
Application.ScreenUpdating = False
r = Sheets("差异统计").Cells(Rows.Count, 1).End(3).Row
Sheets("差异统计").Rows("4:" & r + 1).ClearContents
r = 0
For j = 1 To UBound(arr)
If arr(j, 2) = str1 Then
str2 = arr(j, 2) & arr(j, 3) & arr(j, 4) & arr(j, 5)
If Not d.exists(str2) Then
r = r + 1
d(str2) = r
brr(r, 1) = r
brr(r, 2) = arr(j, 2)
brr(r, 3) = arr(j, 3)
brr(r, 4) = arr(j, 4)
brr(r, 5) = arr(j, 5)
brr(r, 6) = arr(j, 6)
Else
rx = d(str2)
brr(rx, 6) = brr(rx, 6) + arr(j, 6)
End If
End If
Next j
arr = Sheets("装箱明细").UsedRange
For j = 1 To UBound(arr)
If arr(j, 2) = str1 Then
str2 = arr(j, 2) & arr(j, 3) & arr(j, 4) & arr(j, 5)
If Not d.exists(str2) Then
r = r + 1
d(str2) = r
brr(r, 1) = r
brr(r, 2) = arr(j, 2)
brr(r, 3) = arr(j, 3)
brr(r, 4) = arr(j, 4)
brr(r, 5) = arr(j, 5)
brr(r, 7) = arr(j, 6)
brr(r, 8) = brr(r, 6) - arr(j, 6)
Else
rx = d(str2)
brr(rx, 7) = arr(j, 6) + brr(rx, 7)
brr(rx, 8) = brr(rx, 6) - brr(rx, 7)
End If
End If
Next j
Sheets("差异统计").[a4].Resize(r, UBound(brr, 2)) = brr
Application.ScreenUpdating = True
End Sub
|
|