|
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Dim ws As Worksheet
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("期初")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:i" & r)
- End With
- ReDim brr(1 To UBound(arr), 1 To 14)
- For i = 1 To UBound(arr)
- brr(i, 1) = arr(i, 1)
- brr(i, 2) = arr(i, 2)
- brr(i, 3) = arr(i, 3)
- brr(i, 4) = arr(i, 4)
- brr(i, 5) = arr(i, 5)
- brr(i, 6) = arr(i, 6)
- brr(i, 10) = arr(i, 7)
- brr(i, 11) = arr(i, 8)
- xm = brr(i, 1) & "+" & brr(i, 2) & "+" & brr(i, 3) & "+" & brr(i, 4) & "+" & brr(i, 5)
- d(xm) = i
- Next
- For Each ws In Worksheets(Array("出库明细", "外加工返库明细"))
- With ws
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- arr = .Range("a2:m" & r)
- For i = 1 To UBound(arr)
- xm = arr(i, 3) & "+" & arr(i, 4) & "+" & arr(i, 5) & "+" & arr(i, 6) & "+" & arr(i, 7)
- If d.exists(xm) Then
- m = d(xm)
- If ws.Name = "出库明细" Then
- brr(m, 7) = brr(m, 7) + arr(i, 8)
- brr(m, 12) = brr(m, 12) + arr(i, 10)
- Else
- brr(m, 8) = brr(m, 8) + arr(i, 8)
- brr(m, 13) = brr(m, 13) + arr(i, 10)
- End If
- End If
- Next
- End With
- Next
- For i = 1 To UBound(brr)
- brr(i, 9) = brr(i, 6) + brr(i, 7) - brr(i, 8)
- brr(i, 14) = brr(i, 11) + brr(i, 12) - brr(i, 13)
- Next
- With Worksheets("出入库情况汇总")
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(brr), UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |
|