Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
Exception: Cell reference out of range expiredsubsalt @ Code.gs:824

I am running this code and getting same error after trying different data values. please help me resolve this error.

function expiredsubsalt()  // Function to Move expired members from Active Memberships to Expired Membership Sheet
// put the variable to pick the last row and last column and put it into expired sheet
{
  var schedSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Active Memberships");
  var archive=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expired Memberships");
  var clno = schedSheet.getLastColumn();
  for(r=schedSheet.getLastRow();r>1; r--) //For loop started for all rows
  {
    
    if (schedSheet.getRange(r,9).getValue()== "Expired")
    { 
      archive.getRange(2,1,archive.getLastRow(),archive.getLastColumn());
      archive.appendRow(schedSheet.getRange(r,1,1,clno).getValues()[0]);
      schedSheet.deleteRow(r);
    }
   if (schedSheet.getRange(r,2).getValue()==""){schedSheet.deleteRow(r)}    
  }

  Logger.log(r)
  Logger.log(clno)
   // archive.getRange('A2:I').removeDuplicates();
   // archive.getRange().sort([{column: 1, ascending: false}, {column: 2, ascending: true}]);

    archive.getRange(r,clno).removeDuplicates();
    archive.getRange(r,clno).sort([{column: 1, ascending: false}, {column: 2, ascending: true}]);

  
}

line no 824 is - archive.getRange(r,clno).sort([{column: 1, ascending: false}, {column: 2, ascending: true}]);

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In these two lines:

archive.getRange(r,clno).removeDuplicates();
archive.getRange(r,clno).sort([{column: 1, ascending: false}, {column: 2, ascending: true}]);

the r variable is being used is the same that was previously used to loop through the first file, and it has a value of 2 regardless of your spreadsheets. Moreover, as it has been said,your code is trying to sort only one cell.

As you probably want to sort and remove duplicates the whole archive spreadsheet, I would suggest changing the ranges to something like:

.getRange(1,1,archive.getLastRow(), archive.getLastColumn())

You can read more about how Google Sheets deals with ranges here and how you can provide different inputs here.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda