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

151
Visualizações
Dropdown list with sheet names. I need to set active sheet in a function based on selection in dropdown

I am stuck. I have a spreadsheet with a dropdown list containing the names of the sheets. Is it possible within a function to set the active spreadsheet to match the dropdown selection

function getNextCell() {
  // Active sheet should reflect dropdown selection
  // to find first empty cell of that sheet by dropdown
  var sheetTo = SpreadsheetApp.getActiveSheet(); 
  var myValues = sheetTo.getRange('A:A').getValues();
  var i;
  for (i = 0; i < myValues.length; i++) {
    if (myValues[i][0] === '')
      return i + 1;
  }
  return i + 1;
}

Sample sheet updated to show current work: https://docs.google.com/spreadsheets/d/1befqsGQvbPfn0XTGrygLOGcrUIMrICUagJVH0S-2rDw/edit?usp=sharing

I should mention I tried an array but that didn't work for me. I may have been utilizing it wrong but am not sure.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Try using this onEdit(e)

function onEdit(e) {
  const sh = e.range.getSheet();
  if(sh.getName() == "Dropdown" && e.range.columnStart == 8 && e.value) {
    e.source.getSheetByName(e.value).activate();
  }
}

You can also create the list of all sheet names for the datavalidation in column H with this:

function makeColumnDropDown(col = 8) {
  const ss = SpreadsheetApp.getActive();
  const list = ss.getSheets().map(sh => sh.getName());
  const r = SpreadsheetApp.newDataValidation().requireValueInList(list);
  const sh = ss.getSheetByName("Dropdown");
  sh.getRange(1,col,100).setDataValidation(r);
}

If you wish to leave some out you may also add a .filter method to the third line and exclude a list of file names. Just ask I show you.

The next empty row is columnHeight + 1

function getColumnHeight(col, sh, ss) {
  var ss = ss || SpreadsheetApp.getActive();
  var sh = sh || ss.getActiveSheet();
  var col = col || sh.getActiveCell().getColumn();
  var rcA = [];
  if (sh.getLastRow()){ rcA = sh.getRange(1, col, sh.getLastRow(), 1).getValues().flat().reverse(); }
  let s = 0;
  for (let i = 0; i < rcA.length; i++) {
    if (rcA[i].toString().length == 0) {
      s++;
    } else {
      break;
    }
  }
  return rcA.length - s;
}
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