If you want Excel to do the operation automatically,
just code it as VBA.
Sub fitLS()
Dim lengthA As Integer
Dim lengthB As Integer
Dim Cull As Single
Dim Fit1 As Single
Dim Fit2 As Single
Dim Fit1B As Single
Dim Fit2B As Single
Dim kg As Integer
lengthB = Range("Bcol").Count 'length of B
For kg = 1 To lengthB - 1 'for each B
Cull = Range("Acol").Cells(kg, 1) 'store A cull
Fit1 = Range("FitAB").Cells(kg, 1) 'store fit
Fit2 = Range("Sumfit") 'store least squares
lengthA = Range("Acol").Count 'new length of A
Range("Acol").Range(Cells(kg + 1, 1), Cells(lengthA, 1)).Copy _
Range("Acol").Range(Cells(kg, 1), Cells(lengthA - 1, 1)) 'shift up,
Range("Acol").Cells(lengthA, 1).ClearContents 'same as delete
Fit1B = Range("FitAB").Cells(kg, 1) 'store new fit
Fit2B = Range("Sumfit") 'store new least squares
If Fit1B Fit1 Or Fit2B Fit2 Then 'if delete of A doesn't help
Range("Acol").Range(Cells(kg, 1), Cells(lengthA - 1, 1)).Copy _
Range("Acol").Range(Cells(kg + 1, 1), Cells(lengthA, 1)) 'shift down
Range("Acol").Cells(kg, 1) = Cull 'restore A cull
End If
Next kg
End Sub
On your spreadsheet, add this formula
=SQRT(SUM(FitAB))
and name it Sumfit
|