I have this code, I'm trying to hide some rows based on the result of a filter. Here a sample sheet
Basically, I'm trying to build a bill based on a list of transactions/Clients. I use filter and query to have the transaction I want in the sheet "facture" which is my template for the bill.
In row 1003 I have the total of the bill + VAT I would like to hide rows 19 to 23 if the client's name is not "PUB" I would like to hide rows 1016 to 1042 if the client's name is not VSPE and finally I would like to hide every row between the last row of the bill from row 22 to row 999 that is empty.
function hideBill() {
// Define your variables here
var ss = SpreadsheetApp.getActive();
var facture_sheet = ss.getSheetByName("Facture");
var input_sheet = ss.getSheetByName("Input");
var clientname=input_sheet.getRange("ClientName").getValue();
if(clientname=='PUB'){
facture_sheet.showRows(19,1042);
facture_sheet.hideRows(1018,24);
}else if (clientname=='C'){
facture_sheet.hideRows(19,3);
facture_sheet.showRows(22,1022);
}else {
facture_sheet.hideRows(19,3);
facture_sheet.showRows(22,1017);
facture_sheet.hideRows(1018,24);
}
facture_sheet.getRange("a22").activate();
facture_sheet.getRange("a"+(getLastDataRow(facture_sheet)+1)+":g999").activate();
facture_sheet.hideRows(ss.getActiveRange().getRow(), ss.getActiveRange().getNumRows());
facture_sheet.getRange("a22").activate();
}
function getLastDataRow(sheet) {
var lastRow = sheet.getLastRow();
var range = sheet.getRange("e" + lastRow);
if (range.getValue() !== "") {
return lastRow;
} else {
return range.getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
}
}
It is not working correctly and I can't figure out where my mistake is. Can someone help me to find the problem? thanks a lot !! j.