I'm guessing that you want to start with a sheet like Start in the attached.
I've made a copy of that sheet (Start (2)) to experiment on, select that sheet then run the macro blah (Alt+F8 on the keyboard then-double click on the blah macro).
Compare with Sheet1.
The macro:
Sub blah()
For Each are In Cells.SpecialCells(xlCellTypeConstants, 23).Areas
If are.Rows.Count > 1 And are.Columns.Count > 3 Then
Set mycell = are.Cells(are.Rows.Count, 3).Offset(2)
If mycell.Offset(1).Value = "" And mycell.Value = "" Then
mycell.Formula = "=(" & are.Cells(are.Rows.Count, 4).Address & "-" & are.Cells(1, 4).Address & ")/(" & are.Cells(are.Rows.Count, 2).Address & "-" & are.Cells(1, 2).Address & ")"
fr = mycell.Row
lr = are.Row + are.Rows.Count - 1
are.Columns(4).Offset(, 1).FormulaR1C1 = "=RC[-1]-(((RC[-3]-R" & lr & "C[-3])*R" & fr & "C[-2])+R" & lr & "C[-1])"
If are.Column > 6 Then are.Columns(4).Offset(, 2).FormulaR1C1 = "=(RC[-2]-RC[-8])/(RC[-3]-RC[-9])"
End If
End If
Next are
End Sub
It's a start.
Lots of things could make it go wrong.