Search for Values with Wildcard Character

Solution 1:

I believe your goal is as follows.

  • You want to reflect the script for searching the values like Annex01, Annex02 and so on from the column "B" of "LX03SBD" sheet in your script.

In this case, how about using TextFinder? When this is reflected to your script it becomes as follows.

Modified script:

function MoveAllRightRows3() {
  var columnNumberToWatch = 2;
  var valueToWatch = "ANNEX";
  var sheetNameToMoveTheRowTo = "OFFSITE";
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("LX03SBD");
  var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
  
  // Search the values of `Annex01`, `Annex02` and so on from the column "B" of "LX03SBD" sheet.
  var ranges = sheet.getRange(1, columnNumberToWatch, sheet.getLastRow()).createTextFinder(`^${valueToWatch}`).useRegularExpression(true).findAll();

  ranges.reverse().forEach(r => {
    var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    var row = r.getRow();
    sheet.getRange(row, 1, 1, sheet.getLastColumn()).moveTo(targetRange);
    sheet.deleteRow(row);
  });
}
  • When this script is run, the values of Annex01, Annex02 and so on are searcged from the column "B" of "LX03SBD" sheet. And, the searched values are used in the loop.

Reference:

  • createTextFinder(findText) of Class Range