I am very new to JavaScript so please forgive the question if easy.
I have created a Google Sheet. I have used the first tab called Form, to create a data entry form, this data is then saved, using JavaScript to another tab called, Removal_list. All works fine. I have added a search function to recall the data from the Removal_list to Form using names. What I cannot work out is how to show not just the first object that meets the criteria. Example, I will have a list of names (column B in the sheet), which can be duplicated. When I search it will only return the first occurrence. What I would like is the search to allow me to see each occurrence, one at a time. So if John Smith is in my list five times, the first occurrence will populate (as it does now), if this is not the one I want to see then, I somehow, move on to the next occurrence.
// search values
var SEARCH_COL_IDX = 1
function Search() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formS = ss.getSheetByName("Form");
var valuesFound = false;
var str = formS.getRange("D18").getValue();
var values = ss.getSheetByName("Removal_list").getDataRange().getValues();
for (var i = 0; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] == str) {
formS.getRange("B5").setValue(row[0]);
formS.getRange("B7").setValue(row[1]);
formS.getRange("B9").setValue(row[2]);
formS.getRange("B11").setValue(row[3]);
formS.getRange("B13").setValue(row[4]);
formS.getRange("B15").setValue(row[5]);
formS.getRange("E5").setValue(row[6]);
formS.getRange("E7").setValue(row[7]);
formS.getRange("E9").setValue(row[8]);
formS.getRange("E11").setValue(row[9]);
formS.getRange("E13").setValue(row[10]);
formS.getRange("E15").setValue(row[11]);
formS.getRange("G9").setValue(row[12]);
formS.getRange("G11").setValue(row[13]);
formS.getRange("G14").setValue(row[14]);
valuesFound=true;
return;
}
if(valueFound=false){
var ui=SpreadsheetApp.getUi();
ui.alert("No record found");
}
}}