The below code will find NAME 1 and replace it with NM1 as per the replaceInSheet line of code
I would like the code to look at a list of data in SHEET 2 to do the Find&Replace IN SHEET 1. So Column A has names and is repalced by what is in Column B
function runReplaceInSheet() {
var spreadsheet = SpreadsheetApp.openById(""); // UPDATE ID
var sheet = SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]); // UPDATE number in square
brackets
var range = sheet.getRange("F2:F");
// get the current data range values as an array
// Lesser calls to access the sheet, lower overhead
var startRow = 2; // First row of data to process. start at Row 3
var numRows = 2; // Specify what column to look at.
// Fetch the range of cells
var dataRange = sheet.getRange(startRow, 150 , numRows, 1) // Numbers of rows to process
// Fetch values for each row in the Range
var data = dataRange.getValues();
for (var i = 0; i < data.length; ++i) {
var row = data[i];
var v = row[2]; // edit: don't need this
var values = range.getValues();
replaceInSheet(values, 'Name 1', 'N1');
replaceInSheet(values, 'Name 2', 'N2');
//write the updated values to the sheet, again less call;less overhead
range.setValues(values);
} }
function replaceInSheet(values, to_replace, replace_with) {
//loop over the rows in the array
for (var row in values) {
//use Array.map to execute a replace call on each of the cells in the row.
var replaced_values = values[row].map(function(original_value) {
return original_value.toString().replace(to_replace, replace_with);
});
//replace the original row values with the replaced values
values[row] = replaced_values;
}}
I would like the code to look at a list of data in SHEET 2 to do the Find&Replace IN SHEET 1. So Column A has names and is repalced by what is in Column B
and your sample image. In order to correctly understand about your current issue and goal, can you provide the sample input and output you expect? – Tanaike