Mohamed H
Mohamed H

Reputation: 258

Copy format of previous row when Gforms is submitted

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

Answers (1)

Tanaike
Tanaike

Reputation: 201553

  • You want to copy the format from the row 3 to the last row on the active sheet.
  • You want to run the function CopyFormatting(), when the Google Form was submitted.
    • Your script is the container-bound script of Spreadsheet which put the values from Google Form.
  • You want to achieve this using Google Apps Script.

If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.

Modification points:

Modified script:

When your script is modified, please modify as follows.

From:
RefRow.copyTo(LastRow, {formatOnly: true});
To:
RefRow.copyTo(SheetResponse.getRange(LastRow, 1), {formatOnly: true});

Note:

  • If you want to copy the format to the next row of the last row, please modify getRange(LastRow, 1) to getRange(LastRow + 1, 1).
  • In your script, 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.
  • If you want to copy the format of the previous row of the last row to the last row, please modify to var RefRow = SheetResponse.getRange(SheetResponse.getLastRow() - 1, 1, 1, SheetResponse.getLastColumn()).

References:

If I misunderstood your question and this was not the result you want, I apologize.

Upvotes: 6

Related Questions