Hello, for the first stock the following code could help:
Sub T_1()
Dim Stock(31, 5)
r = 3 Charge = 0
For i = 0 To 31
Stock(i, 0) = Cells(r, 1)
Stock(i, 1) = Cells(r, 2)
Qu = CDate(Format(CDate(DateAdd("q", i, #1/1/2011#)), "q-YYYY"))
Ch_Date = CDate(Format(Cells(r, 4), "q-YYYY"))
If Ch_Date > Qu Then
Stock(i, 3) = Qu
Stock(i, 4) = Charge
Stock(i, 5) = "Q" & Format(Qu, "q-YYYY")
Else
Stock(i, 3) = Cells(r, 4)
Stock(i, 4) = Cells(r, 5)
Stock(i, 5) = Cells(r, 6)
Charge = Stock(i, 4)
r = r + 1
End If
Next
i Cells(3, "O").Resize(32, 6) = Stock
End Sub
Can you add the loop for all stocks? regards