|
本帖最后由 烟火孤星泪 于 2024-9-18 20:25 编辑
运行时提示错误,是对象不对吗?
- Sub 批量生成()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- With Worksheets("消费明细")
- .AutoFilterMode = False
- r =.Cells(.Rows.Count, 1).End(xlUp).Row
- arr =.Range("a2:g" & r)
- End With
- For i = 1 To UBound(arr)
- rq = DateValue(arr(i, 5))
- sj = TimeValue(arr(i, 5))
- If Not d.exists(arr(i, 7)) Then
- Set d(arr(i, 7)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 7)).exists(arr(i, 3)) Then
- Set d(arr(i, 7))(arr(i, 3)) = CreateObject("scripting.dictionary")
- End If
- If Not d(arr(i, 7))(arr(i, 3)).exists(rq) Then
- ReDim brr(1 To 11)
- brr(1) = arr(i, 3)
- brr(2) = arr(i, 4)
- brr(3) = rq
- brr(11) = arr(i, 7)
- Else
- brr = d(arr(i, 7))(arr(i, 3))(rq)
- End If
- n = 0
- If sj >= #5:00:00 PM# Then
- n = 4
- ElseIf sj >= #11:00:00 AM# And sj <= #1:00:00 PM# Then
- n = 5
- ElseIf sj >= #6:30:00 AM# And sj <= #9:00:00 AM# Then
- n = 6
- End If
- If n <> 0 Then
- brr(n) = brr(n) + Val(arr(i, 6))
- End If
- d(arr(i, 7))(arr(i, 3))(rq) = brr
- Next
- ReDim crr(1 To d1.Count, 1 To 10)
- ReDim drr(1 To 10)
- drr(1) = "合计"
- m = 0
- For Each aa In d1.keys
- brr = d1(aa)
- For j = 7 To 9
- brr(10) = brr(10) + brr(j)
- Next
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- For j = 2 To 10
- drr(j) = drr(j) + brr(j)
- Next
- Next
- With Worksheets("全校统计")
- .Select
- .UsedRange.Offset(1, 0).Clear
- .Range("a2").Resize(UBound(crr), UBound(crr, 2)) = crr
- .Cells(1 + UBound(crr) + 1, 1).Resize(1, UBound(drr)) = drr
- With.Range("a1").Resize(1 + UBound(crr) + 1, UBound(crr, 2))
- .Borders.LineStyle = xlContinuous
- With.Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- Application.ScreenUpdating = True
- MsgBox "所有报表已生成!"
- End Sub</span>
复制代码 |
|