Alex
Alex

Reputation: 102

Google Apps Script in Google Sheet - Convert formulas to static values - cell function to value

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.

Upvotes: 2

Views: 9336

Answers (1)

Alan Wells
Alan Wells

Reputation: 31310

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

Upvotes: 3

Related Questions