Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda