Don't use several onEdit
-functions. Places place both IF
-statements in the same tag.
Also, you shouldn't have semicolons after the IF
-statements brackets.
function onEdit() {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "General Meeting Attendance Roster" ) { //checks that we're on the correct sheet
s.getRange('S6').setValue("Roster last updated: " + (new Date()));
}
if( s.getName() == "Master Chapter Roster" ) { //checks that we're on the correct sheet
s.getRange('K1').setValue("Chapter Roster last updated: " + (new Date()));
}
}
By default, vlookup
assumes the data is sorted, and finds the largest element that is less than or equal to the search key. Therefore, you should fill the table with the lower bound for each range:
+-------+--------+-------+---------+
| Minor | Normal | Major | Item |
| 1 | 1 | 1 | Arrow |
| 5 | 11 | 11 | Weapons |
| 10 | 21 | 21 | Potion |
| 45 | 32 | 26 | Ring |
+-------+--------+-------+---------+
Let's say the above is your range B2:E6. The first step is to filter the columns, so that only two are left: one of the first three, and the last one. For this I would use filter
based on regexmatch
:
=filter(B2:E6, regexmatch(B2:E2, "^("&A1&"|Item)$"))
For example, if A1 has "Normal" (my favorite mode) then the regular expression is "^(Normal|Item)$" which matches either of two words, and nothing else. So, if we don't do anything else, the result is
+--------+---------+
| Normal | Item |
| 1 | Arrow |
| 11 | Weapons |
| 21 | Potion |
| 32 | Ring |
+--------+---------+
But of course we don't stop here: the filtered columns should be fed into vlookup
:
=vlookup(A2, filter(B2:E6, regexmatch(B2:E2, "^("&A1&"|Item)$")), 2)
And that is the formula you want. For example, if A2 is 15, then the largest entry that is <=A2 is 11, so the returned value is "Weapons".
Best Answer
Use this
map-reduce
pattern to calculate the row-by-row sum: