Reputation: 258
When I submitted a Google forms, I would like copy paste the format of row n°3 (considered as reference) in last line created by the form submissions in the google sheet "responses". Hereafter my code:
function CopyFormatting() {
//Déclaration des variables
var SheetResponse = SpreadsheetApp.getActiveSheet(); //Sheet of forms response
var LastRow = SheetResponse.getLastRow(); //last row of sheet (n)
var RefRow = SheetResponse.getRange("3:3"); //Row n°3 considered as reference
//Copy formatting to last row from reference row
RefRow.copyTo(LastRow, {formatOnly: true});
}
Thank you in advance for support
Upvotes: 2
Views: 1235
Reputation: 201553
CopyFormatting()
, when the Google Form was submitted.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
LastRow
of RefRow.copyTo(LastRow, {formatOnly: true})
is the number. In this case, please use the range object.CopyFormatting()
when the Google Form was submitted, please install the OnSubmit event trigger to the function CopyFormatting()
.When your script is modified, please modify as follows.
From:RefRow.copyTo(LastRow, {formatOnly: true});
To:
RefRow.copyTo(SheetResponse.getRange(LastRow, 1), {formatOnly: true});
getRange(LastRow, 1)
to getRange(LastRow + 1, 1)
.SpreadsheetApp.getActiveSheet()
is used. So in this case, the 1st tab is used. If you want to run the script to the specific tab in the Spreadsheet, please use SpreadsheetApp.getActiveSpreadsheet().getSheetByName("### sheet name ###")
instead of that.var RefRow = SheetResponse.getRange(SheetResponse.getLastRow() - 1, 1, 1, SheetResponse.getLastColumn())
.If I misunderstood your question and this was not the result you want, I apologize.
Upvotes: 6