Editing a Numbers script to enter form data in the first empty line of a table with a last header row
I would need some help to edit a script.
The current one allows me to fill in the table starting from a form and it does it by adding a line, but it doesn't work if the last header line.
I would need you to enter the form data in the first empty line of the table even with the last header line. A big thank you to those who can help me.
This is the script text I'm using now.
// get the two tables involved
var Numbers = Application("Numbers");
var database = Numbers.documents[0].sheets[0].tables["Anagrafe 2025"];
var form = Numbers.documents[0].sheets[1].tables["FORM"];
// get all the values from the form
var values = [];
for(var i=0;i<form.rows.length;i++) {
var value = form.rows[i].cells[0].value();
values.push(value);
}
// create a new row at the bottom of the database
var newRow = database.cells["A"+database.rows.length].addRowBelow();
// put the values into that row
for(var i=0;i<values.length;i++) {
newRow.cells[i].value = values[i];
}
// clear out the form, going backwards so to end on the first cell
for(var i=form.rows.length-1;i>=0;i--) {
form.rows[i].cells[0].value = "";
}
[Re-Titled by Moderator]
iMac 21.5″, macOS 10.15