|
本帖最后由 zxsea_7426 于 2022-11-29 20:13 编辑
原代码修改如下:
Sub 明细周汇总()
Application.ScreenUpdating = False
md = Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
Rows.EntireRow.Hidden = False
a = [a1].CurrentRegion
For i = UBound(a) To 2 Step -1
If InStr(1, a(i, 1), "M", 1) <> 0 Then 'If Mid(a(i, 1), 2, 1) = "M" Then
Range(i & ":" & i).Delete
End If
Next
a = [a1].CurrentRegion
col = UBound(a, 2)
ReDim s(1 To col)
ReDim av(1 To col)
For i = 2 To UBound(a)
d = Day(a(i, 1)): m = Month(a(i, 1))
If d = 1 Then w = 0
For j = 2 To col - 1
' For j = 2 To col
If d Mod 7 = 1 Then s(j) = 0
s(j) = s(j) + a(i, j)
Next
' s(col) = a(i, col)
s(9) = s(7) / s(8)
If d Mod 7 = 0 Then
r = r + 1: w = w + 1
Cells(i + r, 1).EntireRow.Insert
Cells(i + r, 1) = m & "M" & w & "W" 'M月W周
For j = 2 To col
If d = 7 Then av(j) = 0
Cells(i + r, j) = s(j): av(j) = av(j) + s(j)
Next
Range(Cells(i + r - 7, 1), Cells(i + r - IIf(i + md(m) - d <= UBound(a), 0, 1), 1)).EntireRow.Hidden = True
End If
If d = md(m) Then
r = r + 1
Cells(i + r, 1).EntireRow.Insert
Cells(i + r, 1) = m & "M"
For j = 2 To col - 1
Cells(i + r, j) = (av(j) + IIf(d <> 28, s(j), 0)) '/ (w + d Mod 7)
Next
'==========================================
Cells(i + r, col) = Cells(i + r, col).Offset(0, -2) / Cells(i + r, col).Offset(0, -1)
'==========================================
Range(Cells(i + r - (d - 1) Mod 7 - 1, 1), Cells(i + r - 1, 1)).EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|