Use Google Sheets Right Formula in Scripts

Use Google Sheets Right Formula in Scripts

I have a spreadsheet with a bunch of numbers in one column. How can I use google sheets RIGHT formula to take the last 4 numbers and paste them into the adjacent column? I am trying to write a function in Google Apps Script for this. There isn't much documentation on this so I am lost.

5

1 Answer

Explanation:

  • One way to implement the RIGHT google sheets formula in google scripts is to get the desired value as a string and then use slice(-4) to get the last 4 digits of that number. Of course there are many ways to achieve the same goal but this is just one of them.

  • To get the value of a cell as a string, you can use getDisplayValue(). The following script will get the display value of cell A1 and it will set the value of B1 to the last 4 digits of cell A1.

James H. Sterling
Author

James H. Sterling

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.