I have 2 sheets "Main" and "Data Storage"
Main: should allow me to search "Data Storage" and locate information form any column(let say Column B') and provide me with information within the entire row belonging to column "B" which has been successful…somewhat, i used "Jane dowe" and was able to get information, but when i tried using other data within the row the script ran but came up blank
issue: I need to be able to use any veritable of column B' to locate information with in the row
What I have so far is :
var SPREADSHEET_NAME = "Data Storage";
var SEARCH_COL_IDX = 1;
var RETURN_COL_IDX = 0;
function searchStr() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var formSS = ss.getSheetByName("Main"); //Form Sheet
var str = formSS.getRange("I20").getValue();
for (var i = 16; i < values.length; i++) {
var row = values[i];
if (row[SEARCH_COL_IDX] == str) {
formSS.getRange("G3").setValue(row[0]) ;
formSS.getRange("C5").setValue(row[1]);
formSS.getRange("C3").setValue(row[2]);
formSS.getRange("C7").setValue(row[3]);
formSS.getRange("E7").setValue(row[4]);
formSS.getRange("G7").setValue(row[5]);
formSS.getRange("C9").setValue(row[6]);
formSS.getRange("E9").setValue(row[7]);
formSS.getRange("G9").setValue(row[8]);
formSS.getRange("C11").setValue(row[9]);
formSS.getRange("E11").setValue(row[10]);
formSS.getRange("G11").setValue(row[11]);
formSS.getRange("I10").setValue(row[12]);
formSS.getRange("I5").setValue(row[13]);
formSS.getRange("I16").setValue(row[14]);
formSS.getRange("B18").setValue(row[15]);
return row[RETURN_COL_IDX];
}
}
}
Best Answer
You want to enter an employee name, search for that name on another sheet, and return the information for that employee to the initial sheet.
Search Name - Data validation
I simplified the search (and also reduced the risk of error) by using data validation in cell I20 of "Data Storage" - the parameters are "List from a Range", and the range is "Main!C2:C". This range enables you do add more employees to the "Main" sheet and those employee names will automatically appear in the drop down list on "Data Storage".
Processing
getDataRange()
Return the entire data range for "Main" at the outset.indexOf
.var employeedata = datavalues.map(function(e){return e[2];});
var searchresult = employeedata.indexOf(searchname);
var searchdata = data.getRange(searchresult+1, 1, 1, datalastLC).getValues();
var searcdatavertical = searchdata[0].map(function(elem) {return [elem];});
Sample Data
Sample search and output
References
map
indexOf