- Sub qs()
- Dim arr, i, dic
- Set dic = CreateObject("scripting.dictionary")
- With Sheet1
- arr = .Range("a3:p" & .Cells(Rows.Count, 2).End(3).Row)
- ReDim brr(1 To UBound(arr), 1 To 4)
- For i = 1 To UBound(arr)
- x = 0
- s = arr(i, 2) & "|" & arr(i, 7)
- If Not dic.exists(s) Then
- m = m + 1
- dic(s) = m
- brr(m, 1) = arr(i, 2): brr(m, 2) = arr(i, 7)
- x = arr(i, 15) - arr(i, 16)
- If x > 0 Then brr(m, 3) = x Else brr(m, 4) = Abs(x)
- Else
- rw = dic(s)
- brr(rw, 3) = brr(rw, 3) + arr(i, 15): brr(rw, 4) = brr(rw, 4) + arr(i, 16)
- x = brr(rw, 3) - brr(rw, 4)
- If x > 0 Then
- brr(rw, 3) = x: brr(rw, 4) = 0
- Else
- brr(rw, 4) = Abs(x): brr(rw, 3) = 0
- End If
-
- End If
-
- Next i
- .[r3].Resize(m, 4) = brr
- End With
- Set dic = Nothing
- End Sub
复制代码 |