I suspect the following problem. Your formula in say row 22, contains references to cells in row 21 (or ranges inclusive of row 21). If you delete row 21, this will result in #REF! errors (or shrink the inclusive range by 1 row). What I guess you want is for the formula to update to always refer to the row above it (not hard-coded to a row number) or for the range height to stay the same (i.e. always sum five rows above).
To do this, you can use the OFFSET function. Lets say in A22 you put:
=OFFSET(A22,-1,0)
This looks one row above A22 and will return the value in cell A21. However if you delete row 21, the old row 22 will become the new row 21 and update its own formula automatically to =OFFSET(A21,-1,0)
which will now return the value in A20.
OFFSET can also return a range (i.e. five cells above it, in one column) like this:
=SUM(OFFSET(A22,-5,0,5,1))
CAVEAT:
OFFSET is a volatile function and will slow down large workbooks considerably. In such a case, you can use a "relative named range" e.g. called "CellAbove". Learn how to define such a name here: https://exceljet.net/named-ranges (see the section called Named ranges can also be relative although the whole article is excellent at explaining everything you might need to know about named cells and ranges).
SUM
med), absolute cell references may help.