0

I'm currently working on a script that should do the following:

Look at column G5 until G23 if one of those cells in that range is empty it should delete the content of that specific range of row.

i.e. delete content C5 until I5 if G5 is empty.

The code is now checking if column G 5 until G23 is empty, but deletes the whole range instead of only the row of range of the cell that is empty.

I have the following code:

function ClearRangesBasedonEMptyCells() {

  var ss = SpreadsheetApp.getActive();
  var allsheets = ss.getSheets();

  for(var s in allsheets){
    var sheet = allsheets[s];

    // Do not perform the below mentiond loop code on the following sheets
    if(
       (sheet.getName() == "Settings") || 
       (sheet.getName() == "Data")
      ) continue;

   // Perform the below code in a Loop

  // get content column G
    var columnG = ss.getRange("G5:G23").getValue();

    var startRow = 5;  // First row of data to process - We tell the script to start counting from row 5
    var numRows = 19;   // Number of rows to process 

  // Fetch the range of cells B5:D5
  var dataRange = sheet.getRange(startRow, 7, numRows, 1) 

  // Fetch values for each row in the Range.
  var data = dataRange.getValues();
  for (var i = 0; i 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.