Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

380
Views
How to setFormulas() to a range using Google Apps Script?

What do I need to change so that this script sets the formulas (from row 2) to the range defined? The code below doesn't give me any error, but it doesn't set the formulas at all.

  var lc = sheet.getLastColumn();
  var range = sheet.getRange(2, 1, 1, lc);
  var formulas = range.getFormulas();
  
  range.copyFormatToRange(sheet, 1, lc, 3, 3+response); //This pastes the format to the range, whose number of rows is defined depending on the # that the user inputs.

  var pasteTo = sheet.getRange(3, 1, response, lc);//Defines the range for setting formulas
  for (var a = 3; a < response; a++){
    pasteTo = sheet.getRange("A" + a,sheet.getLastColumn());
    pasteTo.setFormulas(formulas);
  }
  }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Doing everything in Arrays is much faster

function kdkdkd() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  const osh = ss.getSheetByName('Sheet1');
  const fA = sh.getRange(2, 1, sh.getLastRow() - 1, sh.getLastColumn()).getFormulas();
  osh.getRange(row,col,fA.length,fA[0].length).setFormulas(fA);  
}

pick whatever you want for row and col

about 4 years ago · Juan Pablo Isaza Report

0

Thank you, @TheMaster, for the orientation: The signature is .getRange('string')(a1notation) or .getRange(number,number)(row, column ), but there's no .getRange('string',number)

Here's how I solved it:

  var lc = sheet.getLastColumn();
  var range = sheet.getRange(2, 1, 1, lc);
  var formulas = range.getFormulas();
  
  range.copyFormatToRange(sheet, 1, lc, 3, 3+response);

  var pasteTo = sheet.getRange(3, 1, response, lc);
  for (var a = 1; a <= response; a++){
    pasteTo = sheet.getRange(a+2,1,1,lc);
    pasteTo.setFormulas(formulas);
    }
  }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!