I have been working on a personal project and encountered a problem where I cannot figure out 'how to obtain the last row of a particular table when there is hidden data such as checkboxes.' I have been researching on the topic and came across a possible solution but I am not sure how to fit it into my code or whether I could incorporate it into mine at all because frankly, I am not very fluent yet in the coding language.
Credit goes to the original writer (https://yagisanatode.com/) for the following code:
function getLastRowSpecial(range){
var rowNum = 0;
var blank = false;
for(var row = 0; row < range.length; row++){
if(range[row][0] === "" && !blank){
rowNum = row;
blank = true;
}
else if (range[row][0] !== ""){
blank = false;
};
};
return rowNum;
};
and here is my current code:
function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var currentSh = event.source.getActiveSheet();
var currentCell = event.source.getActiveRange();
if (currentSh.getName() == 'invoice_approval' && currentCell.getColumn() == 5 && currentCell.getValue()== 'Approved') {
var row = currentCell.getRow();
var numColumns = currentSh.getLastColumn();
var targetSh = ss.getSheetByName('open_invoices');
var target = targetSh.getRange(targetSh.getLastRow()+1, 1);
currentSh.getRange(row,1,1,numColumns).moveTo(target);
currentSh.deleteRow(row);
}
// (Moving back rows <open_invoices to invoice_approval> when a cell's value is changed from 'Approved')
else if (currentSh.getName() == 'open_invoices' && currentCell.getColumn() == 5 && currentCell.getValue()!= 'Approved' ) {
var row = currentCell.getRow();
var targetSh = ss.getSheetByName('invoice_approval');
var target = targetSh.getRange(targetSh.getLastRow()+1, 1);
currentSh.getRange(row,1,1,5).moveTo(target);
currentSh.deleteRow(row);
}
}
I made a sample sheet and listed the problem I am facing:
https://docs.google.com/spreadsheets/d/1Yol5FAa3Sw84zRDanOCILUhD1IWMKjrHAJewT-P18to/edit?usp=sharing