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

452
Views
Google Sheets App Script onChange (evento) para INSERT_COLUMN: ¿cómo obtener qué columna se insertó?
function onInsertColumn(activeRng) { /* I coded this function, and it works, so I'll omit the implementation here because it's irrelevant. But I haven't figured out how to get the active range from the onChange event (to pass to this function).*/ } function onChange(event) { // https://stackoverflow.com/a/66686524/470749 // https://stackoverflow.com/a/64454240/470749 // https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers // https://developers.google.com/apps-script/guides/triggers/events if(event.changeType == 'INSERT_COLUMN'){ const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getActiveSheet() const activeRng = sheet.getSelection().getActiveRange(); // WHAT SHOULD GO HERE? onInsertColumn(activeRng); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Explicación:

Como los usuarios ya han mencionado en los comentarios, depende de cómo se inserte la columna. Si eso se hace manualmente a través de la interfaz de usuario de la hoja de cálculo, puede obtener el número de la columna activa que está seleccionada:

 const colNumber = sheet.getSelection().getActiveRange().getColumn();

y luego cree un objeto de range que representará el rango de columna completo:

 const activeRng = sheet.getRange(1,colNumber,sheet.getMaxRows(),1);

entonces puede alimentar este rango a cualquier función.

Por supuesto, en lugar de getMaxRows() , también puede usar getLastRow() para obtener hasta la última fila con contenido en lugar del rango completo de columnas.

Solución al insertar manualmente una columna:

 function onInsertColumn(activeRng) { // example activeRng.setValue("Selected"); } function onChange(event) { // https://stackoverflow.com/a/66686524/470749 // https://stackoverflow.com/a/64454240/470749 // https://developers.google.com/apps-script/guides/triggers/installable#google_apps_triggers // https://developers.google.com/apps-script/guides/triggers/events if(event.changeType == 'INSERT_COLUMN'){ const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getActiveSheet(); const colNumber = sheet.getSelection().getActiveRange().getColumn(); const activeRng = sheet.getRange(1,colNumber,sheet.getMaxRows(),1); onInsertColumn(activeRng); } }
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!