|
是不是这样子
Sub 按钮1_Click()
Set d = CreateObject("scripting.dictionary")
te = Sheets("结果").Range("b1").Value
lastrow = Sheet1.Cells(Rows.Count, 2).End(xlUp).Row
arr = Sheet1.Range("b1:h" & lastrow)
brr = Array("凭证号", "业务号", "类型", "备注一", "金额")
ReDim arrss(1 To UBound(arr), 1 To 5)
n = 1
For a = 0 To 4
arrss(1, a + 1) = brr(a)
Next
For a = 1 To UBound(arr)
If InStr(arr(a, 6), "凭证号") Then
凭证号 = arr(a, 6)
End If
If arr(a, 1) <> "" And InStr(arr(a, 1), "业务号") = False Then
If arr(a, 5) = te Then
s = arr(a, 5) & arr(a, 2) & 凭证号
d(te & "合计") = d(te & "合计") + arr(a, 7)
If Not d.exists(s) Then
n = n + 1
d(s) = n
arrss(n, 1) = 凭证号
arrss(n, 2) = arr(a, 1)
arrss(n, 3) = arr(a, 2)
arrss(n, 4) = arr(a, 5)
arrss(n, 5) = arr(a, 7)
Else
arrss(d(s), 5) = arrss(d(s), 5) + arr(a, 7)
End If
End If
End If
Next
If d.Count = 0 Then
MsgBox "没有找到数据"
Else
arrss(n + 2, 4) = "合计:"
arrss(n + 3, 4) = "1/2合计:"
arrss(n + 2, 5) = d(te & "合计")
arrss(n + 3, 5) = d(te & "合计") / 2
Sheets("结果").Range("a6").Resize(n + 3, 5) = arrss
End If
End Sub
|
|