Sub specialmacro()
Dim ws As Worksheet
Dim rng1 As Range
Dim celle1 As Range
Dim rng2 As Range
Dim celle2 As Range
Dim pickstart As Date
Dim expiration As Date
Dim pickweek As Long
Dim rng_step As Long
Dim step_counter As Long
Set ws = Sheets("Example-before")
Set rng1 = ws.Range(ws.Cells(2, "A"), ws.Cells(ws.Rows.Count, "A").End(xlUp))
pickweek = 3
step_counter = 0
For rng_step = 0 To 26 Step 13
For Each celle1 In rng1
pickstart = celle1.Offset(0, 3)
expiration = celle1.Offset(0, 4)
Set rng2 = Range(ws.Cells(celle1.Row, "F"), ws.Cells(celle1.Row, "Q")).Offset(0, rng_step)
rng2(1, 12).Offset(0, 1).FormulaR1C1 = "=SUM(RC[-12]:RC[-1])"
rng2.ClearContents
For Each celle2 In rng2
If ws.Cells(1, celle2.Column) >= pickstart _
And ws.Cells(1, celle2.Column) <= expiration Then
celle2 = pickweek
pickweek = pickweek + 1
End If
Next celle2
Next celle1
step_counter = step_counter + 1
pickweek = 3
Next rng_step
End Sub
|