Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy and paste with google spreadsheet script

I would like to modify the script shown below, so that if re-run, it does not overwrite pre-existing data, but instead writes the rows under it.

(I use the google spreadsheet)

moveValuesOnly fonction () {
var ss = SpreadsheetApp.getActiveSpreadsheet ();
var source = ss.getRange ("Sheet1 F1: H3 ');
source.copyTo (ss.getRange ("Feuil2 A1! '), {contentsOnly: true});
source.clear ();
}
like image 473
user2579734 Avatar asked Jul 18 '13 14:07

user2579734


People also ask

How do I automatically copy and paste in Google Sheets?

Here's a shortcut to copy and paste values only in Google Sheets: To copy only the value, highlight it, press “Ctrl” + “Shift” + “C” on your keyboard at the same time. To paste the value, press “Ctrl” + “Shift” + “V” at the same time.

How do I trigger a script in Google Sheets?

Under Run, select the name of function you want to trigger. Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet). Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).

How do you copy and paste a Google spreadsheet with formatting?

To copy a format, press Ctrl+Alt+C (Windows or Chrome OS) or Command+Option+C (Mac). To paste, press Ctrl+Alt+V (Windows or Chrome OS) or Command+Option+V (Mac).


1 Answers

This version will find the first empty row in the destination sheet, and copy the source data so it starts there.

function moveValuesOnly () {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var source = ss.getRange ("Sheet1!F1:H3");
  var destSheet = ss.getSheetByName("Feuil2");
  // Déterminer l'emplacement de la première ligne vide.
  var destRange = destSheet.getRange(destSheet.getLastRow()+1,1);
  source.copyTo (destRange, {contentsOnly: true});
  source.clear ();
}
like image 123
Mogsdad Avatar answered Oct 08 '22 22:10

Mogsdad