Option Explicit
Sub InstallerFormules()
Dim L As Long
For L = 9 To 100 Step 13
Range(Cells(L, "D"), Cells(L, "AD")).FormulaR1C1 = "=IF(ISBLANK(R[-2]C),0,R[-3]C)"
Range(Cells(L + 3, "B"), Cells(L + 8, "B")).FormulaR1C1 = "=""PF ""&ROWS(R" & L + 3 & ":R)"
Cells(L + 3, "C").FormulaR1C1 = "=MIN(R" & L & "C,R" & L + 2 & "C)"
Range(Cells(L + 4, "C"), Cells(L + 8, "C")).FormulaR1C1 = "=MIN(MAX(R" & L & "C-SUM(R" & L + 3 & "C:R[-1]C),0),R" & L + 2 & "C)"
Cells(L + 3, "D").FormulaR1C1 = "=MIN(R" & L & "C,RC3)"
Range(Cells(L + 4, "D"), Cells(L + 8, "D")).FormulaR1C1 = "=MIN(MAX(R" & L & "C-SUM(R" & L + 3 & "C:R[-1]C),0),RC3)"
Range(Cells(L + 3, "E"), Cells(L + 3, "AD")).FormulaR1C1 = "=MIN(R" & L & "C,MAX(RC3-SUM(RC4:RC[-1]:RC4),0))"
Range(Cells(L + 4, "E"), Cells(L + 8, "AD")).FormulaR1C1 = "=MIN(MAX(R" & L & "C-SUM(R" & L + 3 & "C:R[-1]C),0),MAX(RC3-SUM(RC[-1]:RC4),0))"
Range(Cells(L + 10, "D"), Cells(L + 10, "AD")).FormulaR1C1 = "=R[-13]C-SUM(R[-7]C:R[-2]C)"
Next L
End Sub
Option Explicit
Sub InstallerFormules()
Const NumFmt = "0.00" '="0,00" — "General" '="Standard" —
Dim L As Long, L3 As Long, C3 As Long, Cel As Range
[C4:AD6].NumberFormat = NumFmt
For L = 9 To 100 Step 13
Cells(L, "C").FormulaR1C1 = "=SUM(RC4:RC30)"
Range(Cells(L, "D"), Cells(L, "AD")).FormulaR1C1 = "=IF(ISBLANK(R[-2]C),0,R[-3]C)"
Range(Cells(L + 3, "B"), Cells(L + 8, "B")).FormulaR1C1 = "=""PF ""&ROWS(R" & L + 3 & ":R)"
For L3 = 1 To 3
Set Cel = Cells(L + 2 + L3, "C"): If L3 = 3 Then Set Cel = Cel.Resize(4)
Cel.FormulaR1C1 = "=MIN(R" & L & "C" & Choose(L3, "", "-R[-1]C", "-SUM(R" & L + 3 & "C:R[-1]C)") & ",R" & L + 2 & "C)"
For C3 = 1 To 3
Set Cel = Cells(L + 2 + L3, 3 + C3): If L3 = 3 Then Set Cel = Cel.Resize(4)
If C3 = 3 Then Set Cel = Cel.Resize(, 25)
Cel.FormulaR1C1 = "=MIN(R" & L & "C" & Choose(L3, "", "-R[-1]C", "-SUM(R" & L + 3 & "C:R[-1]C)") _
& ",RC3" & Choose(C3, "", "-RC[-1]", "-SUM(RC4:RC[-1])") & ")"
Next C3, L3
Range(Cells(L + 10, "D"), Cells(L + 10, "AD")).FormulaR1C1 = "=R[-13]C-SUM(R[-7]C:R[-2]C)"
[C:AD].Rows(L).NumberFormat = NumFmt
[C:AD].Rows(L + 3).Resize(6).NumberFormat = NumFmt
[C:AD].Rows(L + 10).NumberFormat = NumFmt
Next L
ActiveWindow.DisplayZeros = False
End Sub