Reputation: 27
I wanted to automet some text replacement in a Google sheet.
I utilized the record a macro functionality while doing CTRL-H seacrch and replace, but nothing got recorded.
Then I tryed this code:
spreadsheet.getRange('B:B').replace('oldText','newText');
but it does not work, range has no replace method
Should I iterate each cell?
Upvotes: 2
Views: 1713
Reputation: 201378
oldText
to newText
for the specific column (in this case, it's the column "B".)If my understanding is correct, how about this answer? Please think of this as just one of several answers.
Unfortunately, replace()
cannot be used for the value of getRange()
. So in this answer, I used TextFinder for achieving your goal.
var oldText = "oldText";
var newText = "newText";
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange("B1:B" + sheet.getLastRow()).createTextFinder(oldText).replaceAllWith(newText);
oldText
in the column "B" of the active sheet is replaced to newText
.If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 5