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

199
Visualizações
Google Script to Create Tab Names Based on List

I am very new to Google Apps Scripts, but am working to create a spreadsheet function that will create new tabs based a list of names (in cells C6:C). Some of the cells may not have values in them, so would like to exclude these cells from creating new tabs.

The function works as planned, but after running the script, the new tabs are named with a (1), (2), (3),... etc. after the name that is in the list. For example if the first name in the list is "First Tab", the new tab gets named "First Tab (1)" after my current script is run.

I'm not sure as to what would be causing the numbers in the tab names, so any help would be greatly appreciated!

For reference, Cell B4 contains a count of the number of names in the List that the new Tabs should be created from

'''

function createProjectTabs() {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var range = ss.getRange("C6:C");
var values = range.getValues().filter(String);
var total = ss.getRange('B4').getValue();

for(var k=0; k < total; k++){
  try{
    
    var tabName = range[k][0];
      ss.insertSheet(tabName);}
  catch(err){
    
    tabName = values [k][0]+ " " + k;
    ss.insertSheet(tabName);}
  }
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

function createNonDuplicateProjectTabs() {
  var ss = SpreadsheetApp.getActive();
  const shts = ss.getSheets().map(s => s.getName());
  var sh = ss.getSheets()[0];
  var vs = ss.getRange(6,3,sh.getLastRow()-5,1).getValues().flat();
  vs.forEach(n => {
    if(!~shts.indexOf(n)) {
      ss.insertSheet(n)
    }
  });
}
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