This issue is causing me quite a bit of worry... any help would be much appreciated.
I have have three spreadsheets, A, B, and C (I own all of them). I then create a script that lets one user transfer money from A to C, while another user transfers money from B to C. Both of those users always send the money to the exact same cell in C (let's call that cell "the bank account"). And, the money transfers tend to happen either simultaneously or almost simultaneously, so there is a high risk of collision-errors. And, just in case it matters, the script always runs "as me" (the admin), no matter which user ordered the execution of the script.
So here is the heart of my question: how can I temporarily lock the "bank account" cell in C while someone is transferring money from A to C, and then, once the transfer from A to C is complete, the transfer from B to C will automatically begin? And how can I do this without locking C entirely (a lot of people modify C all the time, and it would disrupt their productivity quite a bit for me to lock the entire spreadsheet, even if just for a few seconds).
Or maybe it would be better to create some sort of buffering system, instead of temporarily locking the cell?
Here is an example of what exactly I meant by "collision-error":
I will use the term "the bank account" to refer to the cell that is receiving the money.
The starting value of the bank account is 100 dollars.
Alice activates a script to add 800 dollars to the bank account and Bob activates a script to add 100 dollars to the bank account.
Alice's script reads the the bank account's current value as 100.
Bob's script reads the bank account's current value as 100.
Alice's script figures that the sum should be 900, and sets the new value of the bank account to be 900.
Bob's script figures that the sum should be 200, and sets the new value of the bank account to be 200.
The final output should have been 1000 dollars, but became 200 instead. So 800 dollars were lost.
Again, any help would be much appreciated.