The script bellow works perfectly for the row in C5. However, I need it to work for the rows below it, separately. An IF check for each row, let's say.

Any thoughts on how to do that?

I tried changing the Range to, for instance, "C5:C10" and G5:Q10, respectively, but it didn't work.

function ClearOKs() {

  var app = SpreadsheetApp;
  var activeSheet = app.getActiveSpreadsheet().getActiveSheet();
  var workingCell = activeSheet.getRange("C5").getValue();
  if(workingCell === ""){
  • Please describe what the script should do and explain what you mean by "it didn't work". If your script is throwing an error, please add it textually. Dec 21, 2020 at 2:35

1 Answer 1


You want to run a script on a single cell, or a range of cells.

Use getCurrentCell() or getActiveRange() to define the rows(s)/column(s) in getRange. This would enable you to select a range and then execute the script on that range.

Current Cell

function theCurrentCell() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var currentCell = sheet.getCurrentCell();
  var cellRow = currentCell.getRow();
  var cellCol = currentCell.getColumn();
  Logger.log("the current cell is "+currentCell.getA1Notation()+", row = "+cellRow+", column = "+cellCol);

Active Range

function theActiveRange() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();
  var currentRange = sheet.getActiveRange();
  var cellRow = currentRange.getRowIndex();
  var cellNumrows = currentRange.getNumRows();
  var cellCol = currentRange.getColumn();
  var cellNumcol = currentRange.getNumColumns();
  Logger.log("the current range is "+currentRange.getA1Notation()+", row = "+cellRow+", number of rows = "+cellNumrows+", col = "+cellCol+", num of columns = "+cellNumcol);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.