|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub TEST4()
Dim arr, brr, i&, j&, R&, dic As Object, vKey
Set d = CreateObject("Scripting.Dictionary")
R = Cells(Rows.Count, 16).End(xlUp).Row
arr = Range("j1:r" & R)
For i = 2 To UBound(arr)
If arr(i, 7) <> "" Then
d(arr(i, 1)) = d(arr(i, 1)) + arr(i, 9) ''累计车费
End If
Next i
For Each k In d.keys
n = 0: hj = 0
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
brr(UBound(brr), 7) = "车费": brr(UBound(brr) - 1, 7) = "合计"
For i = 1 To UBound(arr)
If VBA.Trim(arr(i, 1)) = k Then
n = n + 1
For j = 1 To UBound(brr, 2)
brr(n, j) = arr(i, j)
Next j
hj = hj + arr(i, 7) ''累计金额
End If
Next i
n = n + 1
brr(n, 1) = k
brr(n, 2) = "车费"
brr(n, 6) = "="
brr(n, 7) = d(k) ''车费
n = n + 2
brr(n, 7) = "合计"
brr(n, 8) = Int(hj + d(k)) '''合计
rs = Cells(Rows.Count, 7).End(xlUp).Row
If rs >= 7 Then Range("A7:h" & rs) = Empty
[A8].Resize(n, UBound(brr, 2)) = brr
ActiveSheet.PageSetup.PrintArea = "$A$1:$H$" & n + 7 ''设置打印区域
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & k & Format(Now(), "yyyymmdd")
Next k
Set d = Nothing
End Sub
|
|