|
参与一下,目前完成销项统计- Sub ykcbf() '//2024.1.24
- Dim arr, brr, d, zrr
- Application.ScreenUpdating = False
- Application.DisplayAlerts = False
- Set d = CreateObject("Scripting.Dictionary")
- Set d1 = CreateObject("Scripting.Dictionary")
- Set List = CreateObject("System.Collections.ArrayList")
- Set sh = ThisWorkbook.Sheets("查询")
- With sh
- nf = .[c2]: yf = .[e2]: xm = .[g2]
- End With
- Select Case xm
- Case Is = "销项统计"
- With Sheets(xm)
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:l" & r)
- List.Clear
- For i = 4 To UBound(arr)
- rq = arr(i, 6)
- If Year(rq) = nf And Month(rq) = yf Then
- s = arr(i, 2)
- d1(s) = ""
- s = arr(i, 9)
- If Not List.Contains(s) Then List.Add s
- s = arr(i, 2) & "|" & arr(i, 9)
- d(s) = d(s) + arr(i, 11)
- End If
- Next
- List.Sort
- List.Reverse
- ReDim brr(1 To d1.Count, 1 To 2)
- m = 0
- For Each k In d1.keys
- m = m + 1
- brr(m, 1) = m
- brr(m, 2) = k
- Next
- With sh
- .[a4:j10000] = ""
- .[c3:j3] = ""
- .[a4].Resize(m, 2) = brr
- .[c3].Resize(1, List.Count) = List.toArray
- .Cells(3, List.Count + 3) = "转出"
- arr = .[a3].Resize(d1.Count + 1, List.Count + 2)
- For i = 2 To UBound(arr)
- For j = 3 To UBound(arr, 2)
- s = arr(i, 2) & "|" & arr(1, j)
- arr(i, j) = d(s)
- Next
- Next
- .[a3].Resize(d1.Count + 1, List.Count + 2) = arr
- .[a3].Resize(d1.Count + 1, List.Count + 2).Borders.LineStyle = 1
- End With
- End With
- Case Is = "进项统计"
-
- Case Else
- Exit Sub
- End Select
- Set d = Nothing
- Set d1 = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|