Google Sheets appendRow help starting in new column

Hi im trying to use appendRow to move data. Currently it moves to the first empty cell in column A. I want the data to move to column K-Q row 2 and continue down.

I have included a image to show where i need the inputted data to go.

example

This is what i currently have:

function myFunction() {

const ss = SpreadsheetApp.getActiveSpreadsheet();

//Collect the data.
const sourceRange = ss.getRangeByName("InputData");
const sourceVals = sourceRange.getValues(). flat();


//Validate all cells are filled.
const anyEmptyCell = sourceVals.findIndex(cell => cell == "");
if (anyEmptyCell !== -1){
  const ui = SpreadsheetApp.getUi();
  ui.alert(
    "Input Incomplete",
    "Please enter a value into ALL input cells before submitting.",
    ui.ButtonSet.OK
  );
   return;
};

//gather current dts and user email
const date = new Date();
const email = Session.getActiveUser().getEmail();

const data = [date,email, ...sourceVals];


//Apend the data
const DestinationSheet = ss.getSheetByName("Form");
DestinationSheet.appendRow(data);

//Clear the source sheet rows
 sourceRange.clearContent();

ss.toast("Success Product added to the data log!"); 

Any help would be appreciated.

  • Welcome to Stack Overflow.

    – 

One option is to use the appendRows_() utility function, like this:

  appendRows_(DestinationSheet, data, 'K:K');

For that to work, you will need to paste the appendRows_() and getLastRow_() utility functions in your script project.

Leave a Comment