|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
本帖最后由 ykcbf1100 于 2024-7-11 07:00 编辑
1、文件名时间精确到秒;
2、增加其它项目统计- Sub ykcbf() '//2024.7.10
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set List = CreateObject("System.Collections.ArrayList")
- p = ThisWorkbook.Path & ""
- st = [{"在线","1-3天","3天以上"}]
- rq = Format(Now(), "yyyymmddhhmm")
- p1 = p & "PDF目录" & rq & ""
- rq1 = Format(Now(), "yyyy-m")
- If Not fso.FolderExists(p1) Then fso.CreateFolder p1
- Set sh = ThisWorkbook.Sheets("模版")
- With Sheets("Sheet2")
- r = .Cells(Rows.Count, 1).End(3).Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r, c)
- End With
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- d(s) = ""
- Next
- With Sheets("Sheet3")
- rr = .Cells(Rows.Count, 1).End(3).Row
- cc = .UsedRange.Columns.Count
- zrr = .[a1].Resize(rr, cc)
- End With
- b = Array(3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 12, 14, 15, 2)
- bb = [{7,5,10,4,6,11,9,8}]
- On Error Resume Next
- For Each k In d.keys
- sh.Copy
- Set wb = ActiveWorkbook
- m = 0
- ReDim brr(1 To r, 1 To 20)
- d1.RemoveAll
- List.Clear
- With wb.Sheets(1)
- .Name = k
- .[a1] = "【" & k & "】动态监控工作台账"
- .DrawingObjects.Delete
- For i = 2 To UBound(arr)
- s = arr(i, 1)
- If s = k Then
- s1 = arr(i, 13): s2 = arr(i, 2)
- If Not List.Contains(s2) Then List.Add s2
- If Not d1.exists(s1) Then Set d1(s1) = CreateObject("Scripting.Dictionary")
- d1(s1)(s2) = ""
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = arr(i, 2)
- brr(m, 3) = arr(i, 3)
- brr(m, 5) = arr(i, 4)
- brr(m, 7) = arr(i, 5)
- brr(m, 8) = arr(i, 6)
- brr(m, 9) = arr(i, 7)
- brr(m, 10) = arr(i, 8)
- brr(m, 11) = arr(i, 9)
- brr(m, 13) = arr(i, 10)
- brr(m, 15) = arr(i, 11)
- tmp = ""
- If arr(i, 14) = 1 Then
- tmp = tmp & "/" & arr(i, 2) & ":" & arr(i, 13) & "一次"
- End If
- End If
- Next
- If m > 5 Then
- For x = 1 To m - 5
- .Cells(11 + x, 1).EntireRow.Insert
- Next
- End If
- .[e4] = List.Count
- .Cells(10, 1).Resize(m, 15) = brr
- .Cells(10, 1).Resize(IIf(m < 5, 5, m), 15).WrapText = True
- .Rows(10 & ":" & IIf(m < 5, 5, m) + 9).RowHeight = 30
- .Rows("10:10").Copy
- .Rows("11:" & IIf(m < 5, 5, m) + 9).PasteSpecial Paste:=xlPasteFormats
- Application.CutCopyMode = False
- n = 0
- ReDim crr(1 To 100, 1 To 15)
- ReDim l(1 To 10)
- Sum = 0
- For i = 2 To UBound(zrr)
- If zrr(i, 2) = Empty Then zrr(i, 2) = zrr(i - 1, 2)
- If zrr(i, 14) = Empty Then zrr(i, 14) = zrr(i - 1, 14)
- If zrr(i, 15) = Empty Then zrr(i, 15) = zrr(i - 1, 15)
- If zrr(i, 1) = k Then
- n = n + 1
- crr(n, 1) = n
- For y = 0 To UBound(b)
- crr(n, y + 2) = zrr(i, b(y))
- Next
- Sum = Sum + crr(n, 12)
- l(1) = l(1) + IIf(arr(i, 8) = "设备误报", 1, 0)
- l(2) = l(2) + IIf(arr(i, 8) = "风险属实", 1, 0)
- For j = 1 To UBound(bb)
- If arr(i, 8) = "风险属实" Then
- l(j + 2) = l(j + 2) + zrr(i, bb(j))
- End If
- Next
- End If
- Next
- r1 = .UsedRange.Find("委托车辆属实风险统计及上月同比情况").Row
- If n > 3 Then
- For x = 1 To n - 3
- .Cells(r1 + 2 + x, 1).EntireRow.Insert
- Next
- End If
- .Cells(r1 + 2, 1).Resize(n, 15) = crr
- .Cells(r1 + 2, 1).Resize(IIf(n < 3, 3, n), 15).WrapText = True
- .Rows(r1 + 2 & ":" & r1 + 1 + IIf(n < 3, 3, n)).RowHeight = 30
- .Rows(r1 + 2 & ":" & r1 + 2).Copy
- .Rows(r1 + 3 & ":" & r1 + 1 + IIf(n < 3, 3, n)).PasteSpecial Paste:=xlPasteFormats
- Application.CutCopyMode = False
- r2 = .Columns(2).Find("风险预警").Row
- t1 = d1(st(1)).Count: t2 = d1(st(2)).Count: t3 = d1(st(3)).Count
- .Cells(r2 - 1, 3) = "当月委托监控(" & List.Count & ")辆车辆中,共有(" & t1 & ")辆车当月在线、(" & t2 & ")辆车连续1-3天未上线、(" & t3 & ")辆车连续4-7天以上未上线。"
- .Cells(r2, 3) = "当月处置省智能监管系统各类风险预警(" & Sum & ")宗,经核实,设备误报(" & l(1) & ")宗;属实风险(" & Sum-l(1) & ")宗。其中,属实的风险预警中,接打电话(" & l(3) & ")宗,抽烟(" & l(4) & ")宗,玩手机(" & l(5) & ")宗,超速(" & l(6) & ")宗,超时驾驶(" & l(7) & ")宗,未系安全带(" & l(8) & ")宗,双手脱靶(" & l(9) & ")宗,设备遮挡失效(" & l(10) & ")宗"
- .Cells(r2 + 1, 3) = IIf(Mid(tmp, 2) = "", "无", Mid(tmp, 2))
- r = .Cells(Rows.Count, 1).End(3).Row
- .Cells(r, 1) = "【" & k & "】安全管理人员签名:"
- .ExportAsFixedFormat Type:=xlTypePDF, Filename:=p1 & rq1 & k & ".PDF"
- End With
- wb.Close
- Next
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|