|
再加个班级排序- Sub ykcbf() '//2024.8.23 伙食退费汇总,加个合计行,再加个班级
- Set fso = CreateObject("scripting.filesystemobject")
- Set d = CreateObject("Scripting.Dictionary")
- Application.ScreenUpdating = False
- Dim tm: tm = Timer
- Set sh = ThisWorkbook.Sheets("伙食汇总")
- p = ThisWorkbook.Path & ""
- With Sheets("班级序列")
- r = .Cells(Rows.Count, 1).End(3).Row
- px = Application.Transpose(.[b2].Resize(r - 1, 1))
- End With
- ReDim brr(1 To 10000, 1 To 100)
- On Error Resume Next
- For Each f In fso.GetFolder(p).Files
- If LCase$(f.Name) Like "*保教退费*.xls*" Then
- If InStr(f.Name, ThisWorkbook.Name) = 0 Then
- fn = fso.GetBaseName(f)
- yf = Val(fn)
- n = 3 + yf
- Set wb = Workbooks.Open(f, 0)
- For Each sht In wb.Sheets
- If sht.Name <> "班级序列" Then
- With sht
- bm = .Name
- arr = .UsedRange.Value
- Set Rng = .UsedRange.Find("序号")
- bt = Rng.Row
- For i = bt + 1 To UBound(arr)
- If Val(arr(i, 4)) > 0 Then
- s = bm & "|" & arr(i, 2) '//班级+姓名
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = m
- brr(m, 2) = bm
- brr(m, 3) = arr(i, 2)
- End If
- r = d(bm & "|" & arr(i, 2))
- brr(r, n) = brr(r, n) + Val(arr(i, 4))
- End If
- Next
- End With
- End If
- Next
- wb.Close False
- End If
- End If
- Next f
- With sh
- bt = 3
- .UsedRange.Offset(bt).Clear
- With .Cells(bt + 1, 1).Resize(m, 18)
- .Value = brr
- .Borders.LineStyle = 1
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- End With
- For i = bt + 1 To m + bt
- .Cells(i, 16) = Application.Sum(.Cells(i, 4).Resize(, 12))
- Next
- Set Rng = .Cells(bt + 1, 2).Resize(m, 17)
- With ActiveSheet.Sort
- .SortFields.Clear
- .SortFields.Add2 Key:=Rng.Columns(1), SortOn:=0, Order:=1, CustomOrder:=Join(px, ",")
- .SetRange Rng
- .Header = 2 '//不含标题行
- .Apply
- End With
- For j = 4 To 16
- .Cells(bt, j) = Application.Sum(.Cells(bt + 1, j).Resize(m))
- Next
- .UsedRange.Offset(m + bt).Clear
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "共用时:" & Format(Timer - tm) & "秒!"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|