Api.RecalculateAllFormulas(); inside loop work incorrect

Hello. I have encountered a situation of incorrect work of
Api.RecalculateAllFormulas();

I want to change the values in the cells that the formula uses in a loop, immediately recalculate and insert at each iteration the updated result in the desired order.
At first the function worked with a shift by one iteration, i.e. instead of N the calculation for N -1 was inserted (the initial value before all changes is inserted at the first iteration). Then it started calculating correctly after the second line in a row
Api.RecalculateAllFormulas();
After restarting the application, at some point it started counting incorrectly. If you use it 1 time, it counts with a shift, but the results with incorrect numbers. If you use it 2 times, it counts without shift, but the results are incorrect too. And I can’t get it to work correctly.
It looks like an intermediate calculation gets into the formula, i.e. the recalculation has not been completed, and an intermediate value is taken from the cell with the formula.
Without correct work of
Api.RecalculateAllFormulas();
it is not clear what to do next.
In the macro I tried to implement an analog of Excel data table.
There is no possibility to attach an example here.

The incorrect calculations have been solved (below).
The problem with the shift by one iteration remained, i.e. the formula value calculated at a given iteration will be available only at the next iteration. It is fixed by double insertion
Api.RecalculateAllFormulas();
in a row
The problem with calculations was the following: the value from one cell received in the loop by reference was not perceived in the chain of calculations. After forced deletion of the old reference and insertion of the same new one with clearing the cell format, the calculation became correct.

Hello @8grin4
Sorry for the late reply.
I have increased your forum level, so you can attach files now. As far as I understand, the situation hasn’t been resolved completely. Please provide us with a test file and detailed description how to reproduce the issue. We will take a look at it.