1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| Sub Monthly_Computation()
nb_col = Worksheets("Past & On-going").Range("A2").End(xlToRight).Column
For j = 2 To nb_col
Worksheets("Past & On-going").Columns(j).Activate
Total = Selection.Range("A7").Value - Selection.Range("A6").Value + 1
nb_first = 31 - Day(Selection.Range("A6")) + 1
nb_last = Day(Selection.Range("A7"))
Month_last = Month(Selection.Range("A7"))
If Year(Selection.Range("A7")) = Year(Selection.Range("A6")) + 1 Then
Month_last = Month(Selection.Range("A7")) + 12
End If
nb_inter = Month_last - Month(Selection.Range("A6")) - 1
For i = 1 To 12
If Month(Selection.Range("A6")) = i Then
first_amnt = (nb_first / Total) * Selection.Range("A5").Value
Selection.Range("A" & 11 + i).Value = first_amnt
End If
If Month(Selection.Range("A7")) = i Then
last_amnt = (nb_last / Total) * Selection.Range("A5").Value
Selection.Range("A" & 11 + i).Value = last_amnt
End If
Next i
rest = Selection.Range("A5").Value - first_amnt - last_amnt
For k = 1 To 12
If Month(Selection.Range("A6")) + nb_inter = k Then
If rest > 1 Then
Selection.Range("A" & 11 + k).Value = rest / nb_inter
If nb_inter > 1 Then
For l = Month(Selection.Range("A6")) + 1 To Month(Selection.Range("A6")) + nb_inter - 1
Selection.Range("A" & 11 + l).Value = rest / nb_inter
Next l
End If
End If
End If
Next k
Next j
End Sub |