shengdingb 发表于 2014-2-10 15:40
全分离出来了。麻烦了。,说明在“库存”工作表里 - Private Sub CommandButton1_Click()
- Dim arr, brr(), i&, j&, s$, r, m&, d As Object
- Set d = CreateObject("scripting.dictionary")
- arr = Sheets("出入库记录").Range("A1").CurrentRegion
- ReDim brr(1 To UBound(arr), 1 To 6)
- For i = 2 To UBound(arr)
- s = arr(i, 1) & vbTab & arr(i, 2)
- r = d(s)
- If r = "" Then
- m = m + 1
- d(s) = m
- r = m
- For j = 1 To 3
- brr(m, j) = arr(i, j)
- Next
- brr(m, 4) = arr(i, 6)
- End If
- If arr(i, 4) = "入库" Then
- brr(r, 5) = brr(r, 5) + arr(i, 5)
- ElseIf arr(i, 4) = "出库" Then
- brr(r, 6) = brr(r, 6) + arr(i, 5)
- End If
- Next
- For i = 1 To m
- brr(i, 6) = brr(i, 5) + brr(i, 6)
- Next
- Range("A1").CurrentRegion.Offset(1).ClearContents
- Range("A2").Resize(m, 6) = brr
- End Sub
复制代码 |