Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script to clear a range but keep formulas - Gsheets

Specifically, I need a script to help me clear values from multiple rows but without clearing the formulas on those rows.

I have tried .clearContent which seems to just clear the whole row altogether without any option to keep the formulas.

I know that there might be some add-on that could help on a single sheet but I need to apply the procedure on multiple sheets so I would like to use a script for it.

Thanks!

like image 611
Sid Me Avatar asked Jan 02 '23 19:01

Sid Me


1 Answers

Use range.getFormulas() to store your formulas, then call range.clearContent(), finally paste the formulas back with range.setFormulas().

like image 92
Dean Ransevycz Avatar answered Jan 08 '23 17:01

Dean Ransevycz