I'm trying to do something like this:
a1 = if(a1 = "", b1 + 1, )
…
aN = if(aN = "", b1 + 1, )
b1 = max(a1,1)
The idea is that column A has unique ID's, and b1
keeps the highest generated id until then. The conditional a1 =""
would make sure the function only executes once (for a1 in this case).
This construct would allow me to generate unique ids, that would be stable under row inserts, deletes, etc.
The above fails because the script detect circular references, which is correctly when statically examined I guess.
Is there a way to do something similar without falling onto the circular dependency pit?
Best Answer
With formula's it can't be done, as per your other question, but with a little piece of Google Apps Script you can roughly accomplish what you want.
Code
Explained
From the menu, the script is activated. A prompt is shown and a range is requested. The script will retrieve all data from that range and find the highest value. Afterwards it will evaluate the range for empty entries. Once found, it will add a value (
max + 1
) to that position and re-set the maximum value. At the end of the script all data is added new data to the spreadsheet.Screenshot
before & after
Example
I've created an example file for you: check if cell itself is empty
Add the script under Tools\Script editor from the menu. Press the bug button to authenticate the script.