I have a reading log in a spreadsheet. Column 3 is the book name, 4 is the start page, and 5 is the end page. I want to make a script that could find the current book name in the reading log, then offset(0,2).getValue()
to get the end page, and put it next to the active cell in column 3.
This is what I try:
function OnEdit(e){
var s = e.source.getActiveSheet();
var r = e.source.getActiveCell();
if (r.getColumn() == "3" && r.getValue() != "") {
e.range.offset(0,1).setValue(SpreadsheetApp.getActive().createTextFinder(r.getValue()).findPrevious().offset(0,2).getValue())
}
}
However, this script doesn't work. It doesn't fill in anything at all. I expect the function will do the following:
- When I add a new book name on Column 3, it search at Column 3 for the book name I currently enter, and result the the range of the cell just before this one but not this one.
- Get the cell two column on the right of the result.
- Get its value.
- Put the value in the cell one column on the right of the cell I just edit.
Example:
Book Name | Start Page | End Page |
---|---|---|
1212121 | p.12 | p.13 |
1443444 | p.6 | p.9 |
1212121 [just edited] | [put in p.13] |
Which part of my script is incorrect? The search part? Or other parts?