I've been trying to get the last column's non-empty value based on a matching criteria, which is in a column right next to it. I have this working on via the formula below, but since I got like 10 columns, it takes too long to refresh and I was trying to find a way to have it working via app script.
This is a screenshot of the spreadsheet:

The formula used currently:
=ArrayFormula(IFERROR((INDEX(F$7:F721;MATCH(MAX(IF(B$7:B721=$B722;A$7:A721;0));$A$7:$A721;0)));""))
Obs: It takes too long for the columns to load the results.
The formula I'm trying to use to see if this runs faster, but this one doesn't give me the right result:
=IF($B737="";"";(MAX(FILTER(C7:C736;$B$7:$B736=$B737))))
As for the scripting approach, I have tried a couple of code snipets, since I can't write one myself, but none of them got me to a solution.
Here's the link for an example: https://docs.google.com/spreadsheets/d/133ugcf4LgdOMEv5LKVptjgR1OPKBtIs63BOYdeAFK_o/edit?usp=sharing