2

Is there a Google Apps Script method that will change a cell with a formula to one with a static value?

The reason for this is to avoid lag in the Sheet from lots of cell formulas recalculating as the sheet becomes larger.

I want to make the sheet replace old formulas with static values since they won't be changing.

Alan Wells
  • 30,746
  • 15
  • 104
  • 152
Alex
  • 102
  • 1
  • 10

1 Answers1

3

Use the copyValuesToRange() method:

function copyFormulasToValues() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sourceSheet = ss.getSheetByName("Sheet1");
 var destinationSheet = ss.getSheetByName("Sheet2");

 //getRange(start row, start column, number of Rows, number of Columns)
 var range = sourceSheet.getRange(1,1,1,1); //Copy content of A1

 range
  .copyValuesToRange(destinationSheet, 1, 1, range.getNumRows(), range.getNumColumns());
};

Google Documentation - Link

Alan Wells
  • 30,746
  • 15
  • 104
  • 152