I'm trying to write a function in my google sheet script that will look at two columns that I'm basically using as key-value pairs where I have listed a name and a unique number next to it, and then compare the name key to every name in a Names column and when it finds a match, replace the value in the Names column with the corresponding ID (value). I'm totally new to Google Sheets and google scripts, although I do know JavaScript. I've been working on this for hours and have read through many different tutorials, but I can't figure out my problem. There is only one spreadsheet, if that matters. Here is what I have:
//910 is # rows in the Names column, 250 is # rows in the key-value pairs columns
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var searchRange = sheet.getRange(1, 1, 910, 250);
var rangeValues = searchRange.getValues();
function myFunction(){
for(i=0; i<910; i++){
for(j=0; j<250; j++){
var nameToReplace = rangeValues[i][5]; //(Column E)
var match = rangeValues[j][9]; //key in the key-value pairs (Column I)
var id = rangeValues[j][8]; //value in the key-value pairs (Column H)
if(nameToReplace === match){
nameToReplace.setValue(id);
};
};
};
};
It's currently giving me an error saying "TypeError: nameToReplace.setValue is not a function (line 13, file "Code")". It's fairly simple code so I'm sure it's a simple beginner's mistake but for the life of me I can't figure out what the problem is. TIA!
nameToReplaceis not a range.