|
Sub 统计()
Dim ar As Variant
Dim d As Object, dc As Object
Set d = CreateObject("scripting.dictionary")
Set dc = CreateObject("scripting.dictionary")
With Sheets("消费明细")
r = .Cells(Rows.Count, 1).End(xlUp).Row
If r < 2 Then MsgBox "消费明细为空!": End
ar = .Range("a1:f" & r)
End With
Dim br()
ReDim br(1 To UBound(ar), 1 To 10)
For i = 2 To UBound(ar)
If ar(i, 4) <> "" Then
If IsDate(ar(i, 5)) Then
If Not d.exists(ar(i, 3)) Then Set d(ar(i, 3)) = CreateObject("scripting.dictionary")
d(ar(i, 3))(i) = ""
End If
End If
Next i
For Each k In d.keys
dc.RemoveAll
For Each kk In d(k).keys
rq = CDate(Format(ar(kk, 5), "yyyy/mm/dd"))
If Not dc.exists(rq) Then Set dc(rq) = CreateObject("scripting.dictionary")
dc(rq)(kk) = ""
Next kk
For Each kc In dc.keys
n = n + 1
br(n, 1) = k
br(n, 3) = kc
For Each kkc In dc(kc).keys
br(n, 2) = ar(kkc, 4)
sj = Format(ar(kkc, 5), "h:mm:ss")
If TimeValue(sj) >= TimeValue("17:00:00") Then
br(n, 4) = Val(ar(kkc, 6))
If Val(ar(kkc, 6)) > 10 Then
br(n, 8) = 10
Else
br(n, 8) = Val(ar(kkc, 6))
End If
ElseIf TimeValue(sj) >= TimeValue("11:00:00") And TimeValue(sj) <= TimeValue("13:00:00") Then
br(n, 5) = Val(ar(kkc, 6))
If Val(ar(kkc, 6)) > 14 Then
br(n, 9) = 14
Else
br(n, 9) = Val(ar(kkc, 6))
End If
ElseIf TimeValue(sj) >= TimeValue("6:30:00") And TimeValue(sj) <= TimeValue("9:30:00") Then
br(n, 6) = Val(ar(kkc, 6))
If Val(ar(kkc, 6)) > 5 Then
br(n, 10) = 5
Else
br(n, 10) = Val(ar(kkc, 6))
End If
End If
Next kkc
Next kc
Next k
With Sheets("效果")
.[a1].CurrentRegion.Offset(2).Borders.LineStyle = 0
.[a1].CurrentRegion.Offset(2) = Empty
.[a3].Resize(n, UBound(br, 2)) = br
.[a3].Resize(n, UBound(br, 2)).Borders.LineStyle = 1
End With
MsgBox "ok!"
End Sub
|
|