Imoport daily dat to weekly data with and determine how many monthweek (4 or 5 ) in a month.

minmark

New Member
Joined
Jul 18, 2016
Messages
44
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]

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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top