Home > Mobile >  Google Sheet Script Textfinder Check
Google Sheet Script Textfinder Check

Time:02-11

Hi I'm using this code to get a list of rows that matches the searchtext from column "A" and that works great . But what I'm trying to do is insert a checkmark in column C for each row that match So basically how would I use the array from .map((r) => r.offset(0,3).getA1Notation()) to insert a checkmark on those rows in column "C"

Thanks

function check(){
  var rangeList = SpreadsheetApp.getActive().getSheetByName('sheet1').getRange('A2:A');
  var searchText = "dog";
  .createTextFinder(searchText)
  .matchEntireCell(true)
  .findAll()
  .map((r) => r.offset(0,3).getA1Notation())
  
   console.log(rangeList);
}

CodePudding user response:

From how would I use the array from .map((r) => r.offset(0,3).getA1Notation()) to insert a checkmark on those rows in column "C", in this case, how about the following modification?

Modified script:

function check() {
  var searchText = "dog";

  var sheet = SpreadsheetApp.getActive().getSheetByName('sheet1');
  var rangeList = sheet
    .getRange('A2:A')
    .createTextFinder(searchText)
    .matchEntireCell(true)
    .findAll()
    .map((r) => r.offset(0, 2).getA1Notation());
  sheet.getRangeList(rangeList).insertCheckboxes().check(); // or sheet.getRangeList(rangeList).insertCheckboxes();
  console.log(rangeList);
}
  • I think that .createTextFinder(searchText).matchEntireCell(true).findAll().map((r) => r.offset(0,3).getA1Notation()) occurs an error.

  • In the case of .map((r) => r.offset(0, 3).getA1Notation()), an array including A1Notation is returned. You can use this for achieving your goal.

  • When you want to put the checkbox to the column "C", please modify r.offset(0,3).getA1Notation() to r.offset(0, 2).getA1Notation().

  • If you don't want to insert the checked checkboxes, please remove .check().

References:

  • enter image description here

  • Related