Dear Gents,
I have data like following table, and write codes to try get weekly data from daily (because of the format, I can't use pivot table in this case)
I'm not sure how to determine how many monthweek in a month.
Would you please help me figure out how to fix this out? (D =0 to 4 means this month have 5 monthweeks, not
every week have 7 days in a month).
Thanks.
[TABLE="width: 50"]
<tbody>[TR]
[TD]1
[/TD]
[TD]2
[/TD]
[TD]3
[/TD]
[TD]...
[/TD]
[TD]30
[/TD]
[TD]31
[/TD]
[TD]Total
[/TD]
[TD]W1
[/TD]
[TD]W2
[/TD]
[TD]W3
[/TD]
[TD]W4
[/TD]
[TD]W5
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I have data like following table, and write codes to try get weekly data from daily (because of the format, I can't use pivot table in this case)
I'm not sure how to determine how many monthweek in a month.
Would you please help me figure out how to fix this out? (D =0 to 4 means this month have 5 monthweeks, not
every week have 7 days in a month).
Thanks.
[TABLE="width: 50"]
<tbody>[TR]
[TD]1
[/TD]
[TD]2
[/TD]
[TD]3
[/TD]
[TD]...
[/TD]
[TD]30
[/TD]
[TD]31
[/TD]
[TD]Total
[/TD]
[TD]W1
[/TD]
[TD]W2
[/TD]
[TD]W3
[/TD]
[TD]W4
[/TD]
[TD]W5
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
HTML:
With Application
A = .Weekday(.EoMonth(Now(), -1) + 1)
B = .Weekday(.EoMonth(Now(), 0))
C = Day(.EoMonth(Now(), 0))
Dim arr As Variant
Select Case A
Case "1"
arr = Array(-32, -26, -20, -14, -8, -3, 3)
GoTo Inside1
Case "2"
arr = Array(-32, -27, -21, -15, -9, -4, 2)
GoTo Inside1
Case "3"
arr = Array(-32, -28, -22, -16, -10, -5, 1)
GoTo Inside1
Case "4"
arr = Array(-32, -29, -23, -17, -11, -6, 0)
GoTo Inside1
Case "5"
arr = Array(-32, -30, -24, -18, -12, -7, -1)
GoTo Inside1
Case "6"
arr = Array(-32, -31, -25, -19, -13, -8, -2)
GoTo Inside1
Case "7"
arr = Array(-32, -32, -26, -20, -14, -9, -3)
GoTo Inside1
End Select
GoTo stop2:
Inside1:
For D = 0 To 4
For Each cell In Range(Cells(rng.Row, rng.Column + D), Cells(rng.Row + 3, rng.Column + D))
cell.Value = .Average(Range(Cells(cell.Row, cell.Column + arr(D)), Cells(cell.Row, cell.Column + arr(D + 1))))
Next cell
Next D
stop1:
Set rng = rng.Offset(6, 0).Range("A1")
For D = 0 To 4
For Each cell In Range(Cells(rng.Row, rng.Column + D), Cells(rng.Row + 138, rng.Column + D))
If Left(cell, 1) = "W" Then GoTo stop3
cell.Value = Application.Sum(Range(Cells(cell.Row, cell.Column + arr(D)), Cells(cell.Row, cell.Column + arr(D + 1))))
stop3:
Next cell
Next D
stop2:
End With