|
- Sub test()
- Dim r%, i%, m%
- Dim arr, brr, zrr()
- Dim d As Object
- Dim rqmin As Date
- Dim rqmax As Date
- Dim rq1 As Date
- Dim flg As Boolean
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- Set d2 = CreateObject("scripting.dictionary")
- With Worksheets("统计陪餐费")
- rq = .Range("bq1").Value
- End With
- With Worksheets("就餐人数表")
- .AutoFilterMode = False
- r = .Cells(.Rows.Count, 6).End(xlUp).Row
- arr = .Range("a2:a" & r)
- For i = 1 To UBound(arr)
- If Format(arr(i, 1), "yyyymm") = Format(rq, "yyyymm") Then
- d1(arr(i, 1)) = Empty
- End If
- Next
- n = 2
- For Each aa In d1.keys
- d1(aa) = n
- n = n + 3
- If rqmin = #12:00:00 AM# Then
- rqmin = aa
- Else
- If rqmin > aa Then
- rqmin = aa
- End If
- End If
- If rqmax = #12:00:00 AM# Then
- rqmax = aa
- Else
- If rqmax < aa Then
- rqmax = aa
- End If
- End If
- Next
- ls = 1 + d1.Count * 3 + 2
- r = .Cells(.Rows.Count, 6).End(xlUp).Row
- arr = .Range("f2:i" & r)
- End With
- For i = 1 To UBound(arr)
- xm = Right(arr(i, 2), 2)
- Select Case arr(i, 2)
- Case "小工友", "大工友", "其它人员"
- For rq1 = Application.Max(rqmin, arr(i, 3)) To Application.Min(rqmax, arr(i, 4))
- If d1.exists(rq1) Then
- n = d1(rq1)
- If Not d.exists(xm) Then
- Set d(xm) = CreateObject("scripting.dictionary")
- End If
- If Not d(xm).exists(arr(i, 1)) Then
- ReDim brr(1 To ls)
- brr(1) = arr(i, 1)
- Else
- brr = d(xm)(arr(i, 1))
- End If
- brr(n) = 3
- brr(n + 1) = 5
- If arr(i, 2) = "大工友" Or arr(i, 2) = "其它人员" Then
- brr(n + 2) = 5
- End If
- d(xm)(arr(i, 1)) = brr
- End If
- Next
- Case "教师"
- For rq = Application.Max(rqmin, arr(i, 3)) To Application.Min(rqmax, arr(i, 4))
- If d1.exists(rq) Then
- d2(arr(i, 1)) = Empty
- Exit For
- End If
- Next
- End Select
- Next
- If d2.Count <> 0 Then
- Set d("教师") = CreateObject("scripting.dictionary")
- js = d2.keys
- riqi = d1.keys
- m = 0
- For i = 0 To UBound(riqi)
- n = d1(riqi(i))
- If i <> 0 Then
- If riqi(i) <> riqi(i - 1) + 1 Then
- m = m + 2
- End If
- End If
- If m + 1 > UBound(riqi) Then
- Exit For
- End If
- For q = 1 To 2
- If Not d("教师").exists(js(m + q - 1)) Then
- ReDim brr(1 To ls)
- brr(1) = js(m + q - 1)
- Else
- brr = d("教师")(js(m + q - 1))
- End If
- brr(n) = 3
- brr(n + 1) = 5
- brr(n + 2) = 5
- d("教师")(js(m + q - 1)) = brr
- Next
- Next
- End If
- With Worksheets("统计陪餐费")
- .UsedRange.Offset(2, 0).Clear
- With .Range("a3")
- .Value = "陪餐人员"
- .Resize(3, 1).Merge
- End With
- n = 2
- For Each aa In d1.keys
- With .Cells(3, n)
- .NumberFormatLocal = "m月d日"
- .Value = aa
- .Resize(1, 3).Merge
- End With
- With .Cells(4, n)
- .NumberFormatLocal = "[$-zh-CN]aaaa;@"
- .Value = aa
- .Resize(1, 3).Merge
- End With
- .Cells(5, n).Resize(1, 3) = Array("旱", "中", "晚")
- n = n + 3
- Next
- With .Cells(3, n)
- .Value = "顿人次"
- .Resize(3, 1).Merge
- End With
- n = n + 1
- With .Cells(3, n)
- .Value = "金额"
- .Resize(3, 1).Merge
- End With
- With .Range("a3").Resize(3, ls)
- .Interior.Color = 10441261
- .Font.Color = 16777215
- End With
- r = 6
- For Each aa In Array("工友", "教师", "人员")
- If d.exists(aa) Then
- m = 0
- ReDim crr(1 To d(aa).Count, 1 To ls)
- ReDim drr(1 To ls)
- drr(1) = IIf(aa <> "人员", aa & "小计", "其它小计")
- For Each bb In d(aa).keys
- brr = d(aa)(bb)
- For j = 2 To ls - 2
- If Len(brr(j)) <> 0 Then
- brr(ls - 1) = brr(ls - 1) + 1
- brr(ls) = brr(ls) + brr(j)
- End If
- Next
- m = m + 1
- For j = 1 To UBound(brr)
- crr(m, j) = brr(j)
- Next
- For j = 2 To UBound(brr)
- drr(j) = drr(j) + brr(j)
- Next
- Next
- .Cells(r, 1).Resize(UBound(crr), UBound(crr, 2)) = crr
- .Cells(r + UBound(crr), 1).Resize(1, UBound(drr)) = drr
- r = r + UBound(crr) + 1
- End If
- Next
- With .Range("a3").Resize(r - 3, ls)
- .Borders.LineStyle = xlContinuous
- With .Font
- .Name = "微软雅黑"
- .Size = 11
- End With
- End With
- .Columns(1).Resize(, ls).AutoFit
- With .UsedRange
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- End With
- End Sub
复制代码 |
|