After creating a calculator with a google sheet I need to share a forced copy of it (using the "/copy" parameter at the end of the sheet URL).
In the sheet I have inserted many formulas using the IMPORTRANGE function such as the following:
IMPORTRANGE("1AEfVRA0nZG8H3o4PnKUMa69yYXumbECo8wk6C4Cr53Y";"data!D14:G18")
At the moment the user creates a forced copy of the sheet he gets a new ID for the sheet which I can make available in a cell using the custom function: =URL("key")
To make the calculator work correctly, I need that in every formula where the ID "1AEfVRA0nZG8H3o4PnKUMa69yYXumbECo8wk6C4Cr53Y" is replaced with the new ID obtainable through the formula =URL("key") as follow example:
ORIGINAL FORMULA:
IMPORTRANGE("**1AEfVRA0nZG8H3o4PnKUMa69yYXumbECo8wk6C4Cr53Y**";"data!D14:G18")
NEW FORMULA:
IMPORTRANGE("**2AEcVRA0nZE8H3o5PnKUMa70yYXalcECo8wk7A4Cr12Z**";"data!D14:G18")
I tried to create a Macro but in the "replace with" field, if I insert the formula = =URL("key"), the result is that in all formulas I get an error.
I tried to understand if it is possible to create with the ADDRESS and CONCATENATE function the substitution of the ID dynamically in the formula but the result is always exposed as text therefore the formula is not executed but only shown.
At this point I realized that probably the only way to get the result is through a script but I couldn't figure out how.
I can't find solutions and after searching and reading hundreds of posts I decided to ask directly for a possible solution for the specific case.
Is there anyone who could help me?
Is it there a script to get this ID change in all formulas of all sheets by replacing it with the contents of the cell where the ID of the new sheet is made visible (using the formula =URL("key") ) created with the forced copy?
Thank you so much for your help