|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub TEST3()
Dim arr, brr, i&, j&, R&, dic As Object, vKey
Set dic = CreateObject("Scripting.Dictionary")
k = Range("p65536").End(xlUp).Row
arr = Range("j1:p" & k)
For i = 2 To UBound(arr)
If arr(i, 7) <> "" Then
dic(arr(i, 1)) = dic(arr(i, 1)) + 1
End If
Next i
For Each vKey In dic.keys
R = 0: ReDim brr(1 To dic(vKey) + 3, 1 To UBound(arr, 2))
brr(UBound(brr), 6) = "车费": brr(UBound(brr) - 1, 6) = "合计"
For i = 1 To UBound(arr)
If arr(i, 1) = vKey Then
R = R + 1
For j = 1 To UBound(brr, 2)
brr(R, j) = arr(i, j)
Next j
brr(UBound(brr) - 1, 7) = brr(UBound(brr) - 1, 7) + arr(i, 7)
End If
Next i
Range("A7:G28") = Empty
[A8].Resize(UBound(brr), UBound(brr, 2)) = brr
ActiveSheet.PrintOut
Next
Set dic = Nothing
End Sub
Sub TEST4()
Dim arr, brr, i&, j&, R&, dic As Object, vKey
Set dic = CreateObject("Scripting.Dictionary")
k = Range("p65536").End(xlUp).Row
arr = Range("j1:p" & k)
For i = 2 To UBound(arr)
If arr(i, 7) <> "" Then
dic(arr(i, 1)) = dic(arr(i, 1)) + 1
End If
Next i
For Each vKey In dic.keys
R = 0: ReDim brr(1 To dic(vKey) + 3, 1 To UBound(arr, 2))
brr(UBound(brr), 6) = "车费": brr(UBound(brr) - 1, 6) = "合计"
For i = 1 To UBound(arr)
If arr(i, 1) = vKey Then
R = R + 1
For j = 1 To UBound(brr, 2)
brr(R, j) = arr(i, j)
Next j
brr(UBound(brr) - 1, 7) = brr(UBound(brr) - 1, 7) + arr(i, 7)
End If
Next i
Range("A7:G28") = Empty
[A8].Resize(UBound(brr), UBound(brr, 2)) = brr
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=ThisWorkbook.Path & "\" & vKey & Format(Now(), "yyyymmdd")
Next
Set dic = Nothing
End Sub
|
|