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

269
Views
Google Apps Script: obtenga un rango de celdas en lugar de una celda

Comencé a usar Google Apps Script ayer y tengo problemas para ejecutar el código correctamente cuando intento obtener un rango de celdas en lugar de solo una celda.

Este es el código completo, mostrará un mensaje emergente si la condición es verdadera:

 function CheckPlanNumber() { // Fetch the monthly sales var planNumbersRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Plan Numbers").getRange("B2"); var planNumbers = planNumbersRange.getValues(); var ui = SpreadsheetApp.getUi(); // Check totals sales if (planNumbers == "XXXX") { ui.alert('Contact - Plan Number missing!'); } }

Sin embargo, cuando trato de extender el rango a más celdas para pasar por al menos 10 celdas y validarlas, no muestra el mensaje emergente.

 function CheckPlanNumber() { // Fetch the monthly sales var planNumbersRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Plan Numbers").getRange("B2:B10"); var planNumbers = planNumbersRange.getValues(); var ui = SpreadsheetApp.getUi(); // Check totals sales if (planNumbers == "XXXX") { ui.alert('Contact - Plan Number missing!'); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Range.getValues devuelve valores en una matriz bidimensional, por lo que si tiene una tabla como esta

 | | A | B | | --- | --- | ------------ | | 1 | | Plan numbers | | 2 | | 123 | | 3 | | XXX | | 4 | | 456 |

Range.getValues( 'B2:B4' ) devolverá

 [ [ "123" ] , [ "XXX" ] , [ "456" ] ]

Tendrá que recorrer cada valor y compararlos.

 var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Plan Numbers"); var planNumbersRange = sheet.getRange("B2:B10"); var planNumbers = planNumbersRange.getValues(); var ui = SpreadsheetApp.getUi(); for ( var row = 0; row < planNumbers.length; row++ ) { if ( planNumbers[ row ][ 0 ] == "XXXX" || planNumbers[ row ][ 0 ] == "__" ) { ui.alert( 'Contact - Plan Number missing at row ' + ( row + 2 ) ); } }
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!