kando
kando

Reputation: 605

Function which replaces itself with the output of its contents

In Google Sheets, there are multiple methods to convert a cell formula into its output value, but I have not found a function which performs this.

For example, I'd like to run:

=FORMULA2VALUE(RAND())

which would produce a random number and immediately make that number not only the displayed contents of the cell, but the true contents of the cell as well, preventing the cell from immediately overwriting itself with a new random number on the next trigger of RAND() (which is the next change to the sheet).

Does such a function exist?

Upvotes: 0

Views: 199

Answers (2)

Wicket
Wicket

Reputation: 38254

Google Sheets hasn't built-in function as the one that you are looking for. Google Apps Script might be used to create custom functions but these kind of scripts can't overwrite the cell that contains the formula

Using Google Sheets together with Google Apps Script you might create a Google Sheets macro or a regular script, i.e. to calculate a random number and insert it over the selected cell.

Resources

Upvotes: 0

player0
player0

Reputation: 1

this is possible only with a script:

function RI(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

example of a random number between 1 & 20:

=RI(1; 20)

enter image description here



if for some reason you can't use scripts in your project then follow the white fox into the forest of magic

Upvotes: 1

Related Questions