Sindin
Sindin

Reputation: 11

Need assistance with a basic reset script for google spreadsheets

hello i need some help debugging this simple script i compiled to TRY and reset cells F3 all the way down to F338 in google spreadsheets.

function ClearRange()   
{  
  if('H20' => 1)  
  {  
    sheet.getRange('F3:F338').clearContent();  
    sheet.clearcontent('H20');  
  }  
}  

more or less i want it to run on edit, if on edit cell H20 is greater then one (would be awesome if it was anything other then blank but im unsure how to do that) then it would set the range to blank cells. i would then like it to reset cell H20 back to blank or 0 then end the script.

Upvotes: 1

Views: 127

Answers (1)

Quaris
Quaris

Reputation: 359

To return the value of a cell, use something like this:

var sheet = SpreadsheetApp.getActiveSheet();
var cellValue = sheet.getRange('H20').getValue();

You need to manually declare the sheet variable if you want to use .getRange().getValue() or .getDataRange() and a bunch of other stuff. Also note that just typing in 'H20' doesn't return the cell value, it's just interpreted as a string of text.

To detect if H20 is anything other than blank, you could test if the cell value's length is not 0:

if(sheet.getRange('H20').getValue().length != 0)

To also do a .clearContent() on cell H20, you'll need to do the same thing you did with cells F3:F338:

sheet.getRange('H20').clearContent();

To make the function run on an edit, click on the clock-like icon in the script editor, next to the save icon, and create a new trigger for ClearRange.

Upvotes: 1

Related Questions