I am not able to understand why this below script not working on google sheets,
function Find_Multiple_Replace_Multiple(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
var lastRow = sheet.getLastRow();
var range = sheet.getRange(2,1,lastRow,1);
var to_replace = sheet.getRange(2,5,5,1);
var replace_with = sheet.getRange(9,5,1,1);
var data = range.getValues();
var oldValue="";
var newValue="";
var cellsChanged = 0;
for (var r=0; r<data.length; r++) {
for (var i=0; i<data[r].length; i++) {
oldValue = data[r][i];
newValue = data[r][i].toString().replace(to_replace, replace_with);
if (oldValue!=newValue)
{
cellsChanged++;
data[r][i] = newValue;
}
}
}
range.setValues(data);
}
As from the image it can be seen that from E2:E6
needs to be replaced by the cell value E9
in the column range from A2:A16
, earlier i used this same script it was working, don't know why its not and how do i make it to work for multiple find and multiple replace. Any help is greatly appreciated.
I found a similar question and edited the script to match your request, I tested it and it works. I’m sure there is a better way to do it but you can try this code.