|
Sub 客户对账()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim d As Object
Dim arr()
Set d = CreateObject("scripting.dictionary")
ReDim arr(1 To 1000, 1 To 4)
With Sheets("供应商对账")
gys = .[b1]
If gys = "" Then MsgBox "请选择供应商!": End
For Each sh In Sheets(Array("入库明细", "退货明细"))
r = sh.Cells(Rows.Count, 1).End(xlUp).Row
If r > 1 Then
ar = sh.Range("a1:m" & r)
For i = 2 To UBound(ar)
If Trim(ar(i, 13)) = Trim(gys) Then
If Trim(ar(i, 4)) <> Empty Then
t = d(Trim(ar(i, 4)))
If t = "" Then
k = k + 1
d(Trim(ar(i, 4))) = k
t = k
arr(k, 1) = ar(i, 4)
End If
If sh.Name = "入库明细" Then
arr(t, 2) = arr(t, 2) + ar(i, 6)
Else
arr(t, 3) = arr(t, 3) + ar(i, 6)
End If
arr(t, 4) = arr(t, 2) - arr(t, 3)
End If
End If
Next i
End If
Next sh
If k = "" Then MsgBox "没有所选供应商的数据!": End
.UsedRange.Offset(3) = Empty
.[a4].Resize(k, UBound(arr, 2)) = arr
End With
Set d = Nothing
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|