|
本帖最后由 ykcbf1100 于 2024-7-31 08:28 编辑
分周期统计- Sub ykcbf() '//2024.7.31 周、月、年统计
- Dim rq As Date
- Application.ScreenUpdating = False
- Set d = CreateObject("Scripting.Dictionary")
- Set sh = ThisWorkbook.Sheets("汇总分析")
- rq = Date
- yf = DatePart("m", rq)
- nf = DatePart("yyyy", rq)
- zz = DatePart("ww", rq)
- b = [{6,14,22,30,38}]
- fn = [{"应收","实收"}]
- ReDim brr(1 To 1000, 1 To 1)
- On Error Resume Next
- For Each sht In Sheets
- If Val(sht.Name) Then
- With sht
- r = .UsedRange.Find("合计:").Row
- c = .UsedRange.Columns.Count
- arr = .[a1].Resize(r - 1, c)
- For x = 1 To UBound(b)
- If Val(.Cells(3, b(x))) = zz Then jj = j
- Next
- End With
- For i = 6 To UBound(arr)
- s = arr(i, 1)
- If Not d.exists(s) Then
- m = m + 1
- d(s) = m
- brr(m, 1) = s
- End If
- For j = UBound(arr, 2) - 1 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(5, j) & "|" & nf
- d(s) = d(s) + arr(i, j)
- Next
- If sht.Name = CStr(yf) Then
- For j = UBound(arr, 2) - 1 To UBound(arr, 2)
- s = arr(i, 1) & "|" & arr(5, j) & "|" & yf
- d(s) = d(s) + arr(i, j)
- Next
- End If
- If sht.Name = CStr(yf) And jj > 0 Then
- For y = 1 To 2
- s = arr(i, 1) & "|" & fn(y)
- d(s) = d(s) + arr(i, jj - 5 + y) + arr(i, jj - 3 + y) + arr(i, jj - 1 + y) + arr(i, jj + 1 + y)
- Next
- End If
- Next
- End If
- Next
- With sh
- .[b3] = "第" & zz & "周销售额"
- .[d3] = yf & "月销售额"
- .[f3] = nf & "年度销售额"
- .[a5].Resize(12, 7).ClearContents
- If m > 12 Then
- For i = 1 To m - 12
- Cells(5 + i, 1).EntireRow.Insert
- Next i
- End If
- .[a5].Resize(m, 1) = brr
- arr = .[a3].Resize(m + 2, 7)
- For i = 3 To UBound(arr)
- For j = 2 To 3
- s = arr(i, 1) & "|" & arr(2, j)
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- For j = 4 To 5
- s = arr(i, 1) & "|" & arr(2, j) & "|" & yf
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- For j = 6 To 7
- s = arr(i, 1) & "|" & arr(2, j) & "|" & nf
- If d.exists(s) Then
- arr(i, j) = d(s)
- End If
- Next
- Next
- .[a3].Resize(m + 2, 7) = arr
- End With
- Set d = Nothing
- Application.ScreenUpdating = True
- MsgBox "OK!"
- End Sub
复制代码
|
|