So I am trying to create an attendance system. Basically what I want is for people to be able to type in their ID number in a sheet called attendance. Upon entering the information in that column, the adjacent column (column 2) will populate with their name and the next column (the third column) will populate with the time of entry. The time of entry is calculated using new Date(). However I planned on having it retrieve the name from a master list located on a sheet named "list". The "list" sheet has the ID's in column A and the names in Column B. So what I am trying to do is have the google script emulate Vlookup by looking at the recently edited cell, searching that value in "list" column A then return the corresponding "list" column B value in the adjacent column to the cell that was just edited. I want to be able to do this several times throughout the "attendance" sheet. So basically, each day we take attendance will occupy three columns within the "attendance" sheet.
function onEdit(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() === "Attendance") {
var r = e.source.getActiveRange();
if (r.getRow() != 1 && r.getColumn()%3 != 0 && r.getColumn()%3 != 2) {
sheet.getRange(r.getRow(),r.getColumn()+2).setValue(new Date());
var popsheet = SpreadsheetApp.getActiveSpreadsheet.GetSheetByName("list")
var data=popsheet.getRange("A1:D100").getValues();
for(i=0;i<data.length;++i){
if (data[i][0]==r.GetValue()){
sheet.getRange(r.getRow(),r.getColumn()+1).setValue(data[i][1]);
}
}
}
The date populates just fine but the name does not populate. I have not received any error messages. I tried changing everything written after var popsheet = ... to only sheet.getRange(r.getRow(),r.getColumn()+1.setValue("test") and it does in fact return "test" in the adjacent column of the cell edited. So that leads me to believe that the issue is with my attempt to emulate Vlookup.