You can try doing a reverse search only on B column values.
The idea is to fetch the range values, work with them in memory then find the index of the last populated cell.
With this index, you can get the A1 notation from the Range
instance.
Sample code:
function findLastPopulatedA1Ref(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var bcolRange = ss.getRange("B2:B30"); //Getting B column range, arbitrary size. Modify it accordingly
var bcolVals = bcolRange.getValues();
var i; //declaring the index outside loop to reuse it later
for (i = bcolVals.length - 1; i >= 0; i--) { //reversing the loop (end to start) to find the first non-empty cell
if(bcolVals[i] != ""){
console.log(`${i}: bcol[i] == ${bcolVals[i]}`); //(optional) Just for debugging purposes
break; // Forcing the end of the for loop, thus keeping the desired index value in i
}
}
if (i == -1){
console.log("Warning: B column is empty"); //(optional) Just for debugging purposes
return null; //B Column is empty
}
var result = bcolRange.getCell(i+1, 1).getA1Notation(); //getCell starts at (1,1) and js arrays starts at 0. That's the reason to add 1.
console.log(result); //(optional) Just for debugging purposes
return result;
}