Search code examples
google-apps-scriptgoogle-sheetsnamed-ranges

Delete ROW that a namedRange is Associated With in Google Apps Scripts


I know I can delete the actual namedRange, but that is not what I am looking for. I have a cell that has a namedRange associated with it. I want the script to determine what row this cell resides in and delete that entire row.

Doing something like below only deletes the namedRange, not the row it is associated with. Any ideas how I would go about doing that? Thanks!

var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1').getNamedRanges();
    namedRanges('namedRange1').remove();

Solution

  • Try this:

    function delRow(name) {
      var ss=SpreadsheetApp.getActive();
      var rg=ss.getRangeByName(name);
      rg.getSheet().deleteRow(rg.getRow());
    }