Home > OS >  Find and replace text in Google Sheets using TextFinder and Apps Script
Find and replace text in Google Sheets using TextFinder and Apps Script

Time:04-27

I have a code where i want the code to find the symbol " in the active sheet and replace it with a space . I have tested this for a text Example - Tot and the code works fine. is there a way to use the code where it replaces the symbol " with space and and when run. Below the code in use:

function searchAndReplace(searchTerm, replacement)

{textFinder = SpreadsheetApp.getActive().getSheetByName("Sheet1")

.createTextFinder("Tot")

.matchEntireCell(true)

.matchCase(true)

.matchFormulaText(false)

.ignoreDiacritics(false)

.replaceAllWith(" "); }

CodePudding user response:

Try

function searchAndReplace() {
  textFinder = SpreadsheetApp.getActive().getSheetByName("Sheet1")
    .createTextFinder("\"")
    .matchEntireCell(false)
    .matchCase(true)
    .matchFormulaText(false)
    .ignoreDiacritics(false)
    .replaceAllWith(" ");
}

CodePudding user response:

It this case it can be shortened to:

function searchAndReplace() {
  SpreadsheetApp.getActive().getSheetByName('Sheet1').createTextFinder('"').replaceAllWith(' ');
}
  • Related