|
Sub 剩余查询()
Dim ar As Variant
Dim d As Object
Set d = CreateObject("scripting.dictionary")
With Sheets("购买预付")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "购买预付为空!": End
ar = .Range("a1:i" & r)
End With
With Sheets("消费划扣")
rs = .Cells(Rows.Count, 1).End(xlUp).Row
If rs < 2 Then MsgBox "消费划扣为空!": End
br = .Range("a1:i" & rs)
End With
With Sheets("个人剩余信息")
xm = .[a3]
If xm = "" Then MsgBox "请输入要查询的客户名称!": End
ReDim arr(1 To UBound(ar) + UBound(br), 1 To 4)
For i = 2 To UBound(ar)
If ar(i, 4) <> "" Then
If ar(i, 4) = xm Then
t = d(ar(i, 8))
If t = "" Then
k = k + 1
d(ar(i, 8)) = k
t = k
For j = 6 To 8
arr(k, j - 5) = ar(i, j)
Next j
End If
arr(t, 4) = arr(t, 4) + ar(i, 9)
End If
End If
Next i
For i = 2 To UBound(br)
If br(i, 4) <> "" Then
If br(i, 4) = xm Then
t = d(br(i, 8))
If t = "" Then
k = k + 1
d(br(i, 8)) = k
t = k
For j = 6 To 8
arr(k, j - 5) = br(i, j)
Next j
End If
arr(t, 4) = arr(t, 4) - br(i, 9)
End If
End If
Next i
ReDim brr(1 To k, 1 To 4)
For i = 1 To k
If arr(i, 4) <> 0 Then
n = n + 1
For j = 1 To 4
brr(n, j) = arr(i, j)
Next j
End If
Next i
.UsedRange.Offset(10) = Empty
.[a11].Resize(n, UBound(arr, 2)) = brr
End With
MsgBox "ok!"
End Sub
|
|