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

118
Views
Include formulas and data validation for specific columns when creating new tabs from an existing sheet

This google apps (Javascript) formula works perfectly to move data into regional tabs. Is there any way to bring over the formulas and data validation into the new sheets? Column 1-18 are all formulas, and currently only populate with values. I'd like to keep the formulas for column 1-18 and data validation for the remaining columns.

function createSheets() {
  const ss = SpreadsheetApp.getActive()
  const ssh = ss.getSheetByName("Forecast (SQL) Validation");
  const regions = ssh.getRange(3, 24, ssh.getLastRow() - 2, 1).getValues().flat();
  const urA = [...new Set(regions)];
  const shnames = ss.getSheets().map(s => s.getName())
  let ws;
  urA.forEach(region => {
    let idx = shnames.indexOf(region);
    if (~idx) {
      ss.deleteSheet(ss.getSheetByName(shnames[idx]));//if it does exist delete it and create a new one
    }//if it does not exist create a new one
    ws = null;
    
    if(region.length>0)
    {
    ws = ss.insertSheet("R"+region.split("-")[0]);
    ws.getRange("A2").setFormula(`=FILTER('Forecast (SQL) Validation'!A3:CR,'Forecast (SQL) Validation'!X3:X="${region}")`)
    ssh.getRange("A2:CR2").copyTo(ws.getRange("A1:CR1"))

    ws.hideColumns(2,2)
    ws.hideColumns(6,11)
    }
  })
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I notice you are using the copyTo method, it should work and give you both formula and values:

Copies the data from a range of cells to another range of cells. By default both the values and formatting are copied, but this can be overridden using advanced arguments. It should work as suggested over your code.

I am using some of the discussion references that seem to be related to your issue. The solution to this error is to pass an appropriate object, this thread has a great discussion about the matter and a reference on using "contetnsOnlyTrue"

Edit idea that can be done to it based on those threads:

ws.getRange("A2").setFormulasR1C1(`=FILTER('Forecast (SQL) Validation'!A3:CR,'Forecast (SQL) Validation'!X3:X="${region}")`) //adding the formulasr1c1

    ssh.getRange("A2:CR2").copyTo(ws.getRange("A1:CR1"), {contentsOnly:true}) //contentsOnly

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!