Home > OS >  How to round a cell after user input in Google Sheets?
How to round a cell after user input in Google Sheets?

Time:10-24

It should be a very simple function but I can't find anything that functions the way I need. I want to have a cell where a number can be entered, then after its entered it is replaced by that number rounded to its nearest 0.25 For example: I enter 5.26 into cell A1, after i press enter the cell now says 5.25 This should only happen with cell A1, so if i enter 5.26 elsewhere it will stay as 5.26 Any help? Thanks in advance and sorry if this a common question.

CodePudding user response:

This can be achieve by using enter image description here

Triggers let Apps Script run a function automatically when a certain event, like opening a document, occurs. In your case, we need to use onEdit since it runs automatically when a user changes the value of any cell in a spreadsheet. Apps Script passes the triggered function an event object that contains information about the context in which the event occurred (usually named e).

In the demo above, I created a condition that will check if the edited cell is A1 and if the inputted value is number. If both satisfy the condition, the script will calculate the value and use range.setValue() to change the value of A1.

References:

  • Related