I created a Google Spreadsheet that is made up of 20+ sheets (all formatted the same way). The company I work for loads containers. One of those sheets calculates a particular parameter on each of those 20+ sheets (countifs formula) and gives me a total value of how many containers were loaded on that day. For example, say on 11/20/14 we loaded 5 containers on sheet 1, sheet 2 = 6 containers, sheet 3 = 7 containers... etc. It is going to calculate how many total containers were loaded on 11/20/14 and spit out a number. Up to this part I am OK.

The problem is that these sheets need to be cleared and reused once we're finished loading on a sheet. What that means is that when a sheet is processed and cleared, any value attached to the parameter mentioned above is taken away. So if my total value is 20 containers loaded on 11/20/14, and I clear 5 containers on sheet 1, now my value will go down to 15 containers. But in reality, it was 20.

I've tried copying and pasting the end value at the beginning of the next day, before a sheet is processed and cleared, but sometimes, things get out of sync when a sheet is processed and cleared before the beginning of the next day.

Is there any way to have a value automatically set itself after "today" and no longer be associated with the formula?

Again, working with Google Spreadsheet. I'll need step by step help implementing a script if that is the answer.

2 Answers 2


In order to "freeze" the formula output on a summary sheet with a script, you can use copyTo method with the option contentsOnly:true. This can be used to copy the values to another place, or to exactly the same cells (thus, overwriting the formulas with their output). Here is a simple script that does this for cells A1:A10 of the sheet named "SummarySheet".

In order for such a process to run periodically, you have to decide which cells need to be frozen on each day; this is something specific to a particular worksheet.

function freezeOutput(){
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SummarySheet");
  var range = sheet.getRange("A1:A10");     
  range.copyTo(range, {contentsOnly:true});
function RunReplaceInSheet(){
    var sheet = SpreadsheetApp.getActiveSheet()

function replaceInSheet(sheet, to_replace, replace_with) {
  //get the current data range values as an array
  var values = sheet.getDataRange().getValues();

  //loop over the rows in the array
  for(var row in values){

    //use Array.map to execute a replace call on each of the cells in the row.
    var replaced_values = values[row].map(function(original_value){
      return original_value.toString().replace(to_replace,replace_with);

    //replace the original row values with the replaced values
    values[row] = replaced_values;

  //write the updated values to the sheet
  • 1
    A little explanation is more helpful to improve your answer.
    – serenesat
    Oct 26, 2015 at 5:17
  • 1
    Why are you replacing '§' with empty string?
    – user79865
    Oct 27, 2015 at 0:30
  • This is not an answer to OP's question.
    – haridsv
    Feb 15, 2016 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.