简体   繁体   中英

Select cells(Ctrl+A) then Copy range and paste to another sheet's first empty row

I would like to copy a range from a sheet to another sheet's first empty row. But instead of copying the whole spreadseet i want to select the cells (like i do with CTRL+ A) and only the selected(ctrl+A) cells should be copied to another sheet's first row. Here is a script that i found here in stackoverflow and it works but it only copy that range i give for example: sheet1:F1.H3. I want the script to find the cells like ctrl+ A does and then it copies to the other sheet's first empty row.

Thank you so much for your help in advance.

Here is the script:

function moveValuesOnly () {
  var ss = SpreadsheetApp.getActiveSpreadsheet ();
  var source = ss.getRange ("Sheet1!F1:H3");
  var destSheet = ss.getSheetByName("Sheet2");
  // Déterminer l'emplacement de la première ligne vide.
  var destRange = destSheet.getRange(destSheet.getLastRow()+1,1);`enter code here`
  source.copyTo (destRange, {contentsOnly: true});
  source.clear ();
}

Using getDataRange() solved the issue.

As mentioned in the documentation:

Returns a Range corresponding to the dimensions in which data is present.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM