I have a code and the link google sheet
the problem is when I fill in the data and then click on the button Submit at PrintForm sheet the data will be saved to PrintLog sheet but it includes the empty rows
so I would like to remove the empty rows before saving that data to RpintLog sheet but I don’t know how I can handle it, Looking forward to receiving your support
function Printting() {
// We will add our code here.
const ss = SpreadsheetApp.getActiveSpreadsheet();
// collect the data
const sourceRange = ss.getRangeByName("clearRange");
const clearRange = sourceRange.getValues().flat();
const SOLA_sourceRange = ss.getRangeByName("SOLA");
const SOLA_sourceVals = SOLA_sourceRange.getValues().flat();
const SOLB_sourceRange = ss.getRangeByName("SOLB");
const SOLB_sourceVals = SOLB_sourceRange.getValues().flat();
const SOLC_sourceRange = ss.getRangeByName("SOLC");
const SOLC_sourceVals = SOLC_sourceRange.getValues().flat();
const SOLD_sourceRange = ss.getRangeByName("SOLD");
const SOLD_sourceVals = SOLD_sourceRange.getValues().flat();
const SOLE_sourceRange = ss.getRangeByName("SOLE");
const SOLE_sourceVals = SOLE_sourceRange.getValues().flat();
const SOLF_sourceRange = ss.getRangeByName("SOLF");
const SOLF_sourceVals = SOLF_sourceRange.getValues().flat();
const SOLG_sourceRange = ss.getRangeByName("SOLG");
const SOLG_sourceVals = SOLG_sourceRange.getValues().flat();
const SOLH_sourceRange = ss.getRangeByName("SOLH");
const SOLH_sourceVals = SOLH_sourceRange.getValues().flat();
// Gather current dts and user email.
const date = new Date();
const email = Session.getActiveUser().getEmail();
const SOLA_data = [date, email, ...SOLA_sourceVals];
const SOLB_data = [date, email, ...SOLB_sourceVals];
const SOLC_data = [date, email, ...SOLC_sourceVals];
const SOLD_data = [date, email, ...SOLD_sourceVals];
const SOLE_data = [date, email, ...SOLE_sourceVals];
const SOLF_data = [date, email, ...SOLF_sourceVals];
const SOLG_data = [date, email, ...SOLG_sourceVals];
const SOLH_data = [date, email, ...SOLH_sourceVals];
// append the data
const destinationSheet = ss.getSheetByName("PrintLog");
destinationSheet.appendRow(SOLA_data);
destinationSheet.appendRow(SOLB_data);
destinationSheet.appendRow(SOLC_data);
destinationSheet.appendRow(SOLD_data);
destinationSheet.appendRow(SOLE_data);
destinationSheet.appendRow(SOLF_data);
destinationSheet.appendRow(SOLG_data);
destinationSheet.appendRow(SOLH_data);
// clear the source sheet rows
sourceRange.clearContent();
ss.toast("Success: Item Added to the data Log!");
};
2
Answers
Your script does not detect blank rows.
The script shown below identifies the number of rows of data on
PrintForm
and uses this to set thegetRange
andgetValues
. This limits the data to ONLY rows with values and excludes any empty rows.The OP script is idiosyncratic, and doesn’t easily adapt to conversion.
Since you appear to have data in your first column sheet.getLastRow() is not useful to you. Appending rows is quite slow