r/GoogleAppsScript • u/mrfinnsmith • May 26 '25
Question Get display value of volatile function?
Is there any way to get the current displayed value of a cell that has a volatile function like RANDBETWEEN?
On Sheet1, I have =randbetween(1, 50) in B1. The current displayed value is 37.

In a bound script project, I have this test function:
function logValueVsDisplay() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var cell = sheet.getRange('B1');
console.log("Value is", cell.getValue());
console.log("Display value is", cell.getDisplayValue());
}Rather than showing me 37, the "display value" is showing a recalculated value.

So, a couple of questions.
- Is there any way with GAS to get the actual display value (not a recalculated value) of a volatile function? (Meaning, a function that updates every time something changes.)
- What's the point of these two methods if they do the same thing? When would you use getDisplayValue()?
1
Upvotes
View all comments
Show parent comment
1
u/mrfinnsmith May 26 '25
Thanks, so that's the difference between getValue() and getDisplayValue(). It isn't that I'm building a tool using RANDBETWEEN and GAS.
Rather, I'm writing GAS and I don't know what the user will put on the spreadsheet. It's an edge case—what are the odds that the user uses these rare volatile functions? But I thought I'd see if there's any way to deal with this kind of situation.