Good day!
The program that I have posted is already working which does the following :
newOpex(), newMBAP(), and newCashDR() are functions that create a copy of their respective sheets which are copied from a template sheet named templateOpex, templateMBAP, and templateCashDR which is within the spreadsheet. The template sheet is basically an empty form of the sheet of each which is RCDisb (OpEx) : Current, RCDisb (MBAP) : Current, and CashDR : Current. When any of the 3 functions is called, It changes the name of the sheet to its respective number ( Ex.from RCDisb (OpEx) : Current to RCDisb (OpEx) : Sheet #1 ) and changes the newly made sheet to Current.
When the function resetSCA() is called, it copies the spreadsheet into a folder in Google Drive and deletes the sheets inside the Spreadsheet and reproduces a fresh copy of templateOpex, templateMBAP, and templateCashDR ready to be used by the user again.
Now my issue is that, I cant seem to find a way to delete the sheets including the ones that were just added without it touching the DV Logbook and the other Template sheets and without the code failing due to null which is caused by the newly added sheets.
const ws = SpreadsheetApp.getActiveSpreadsheet()
const ws_lb = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DV Logbook");
const ws_opex = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("RCDisb (OpEx) : Current");
const ws_mbap = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("RCDisb (MBAP) : Current");
const ws_cashdr = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CashDR : Current");
//lastrow_indicators
const lastrow_lb = ws_lb.getLastRow();
const lastrow_opex = ws_opex.getLastRow();
const lastrow_mbap = ws_mbap.getLastRow();
const lastrow_cashdr = ws_cashdr.getLastRow();
function newOpex(){
var ui = SpreadsheetApp.getUi();
var rcdisbopex = 1;
var result = ui.prompt(
'