0

I am using below sample code to copy only values from one sheet and paste to another. But here it paste my formula also from source file. I want only value and format(dont want formula) to be copied from source and paste to destination sheet. how it can be done in google spreadsheet scripts?

function copyInfo() { 
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var copySheet = ss.getSheetByName("Copy"); 
  var pasteSheet = ss.getSheetByName("Paste"); 
  // get source range 
  var source = copySheet.getRange(2,2,12,2); 
  // get destination range 
  var destination = pasteSheet.getRange(pasteSheet.getLastRow()+1,2,12,2); 
  // copy values to destination range 
  source.copyTo(destination); 
  // clear source values 
  source.clearContent(); 
}
ross
  • 2,684
  • 2
  • 13
  • 22
PK Inception
  • 141
  • 1
  • 1
  • 4
  • function copyInfo() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var copySheet = ss.getSheetByName("Copy"); var pasteSheet = ss.getSheetByName("Paste"); // get source range var source = copySheet.getRange(2,2,12,2); // get destination range var destination = pasteSheet.getRange(pasteSheet.getLastRow()+1,2,12,2); // copy values to destination range source.copyTo(destination); // clear source values source.clearContent(); } – PK Inception Sep 13 '19 at 19:03
  • https://stackoverflow.com/questions/44967086/copy-data-from-one-sheet-to-another-in-google-app-script-and-append-a-row-one-s/44967382#44967382 – PK Inception Sep 13 '19 at 19:05
  • 1
    Set the option to contents only - `{contentsOnly:true}` [doc ref](https://developers.google.com/apps-script/reference/spreadsheet/range#copytodestination-options) – Tedinoz Sep 15 '19 at 11:19

1 Answers1

0

I have almost same kind of situation. I have to copy data form sheet "Important work" 'range B4 : M getlast row' and paste it into "sheet 8" below last row please correct this code ...

function copyInfo() { 
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var copySheet = ss.getSheetByName("Important work"); 
  var pasteSheet = ss.getSheetByName("Sheet8"); 
  // get source range 
  var source = copySheet.getRange(4,2,copySheet.getLastRow(),13); 
  var source1 = source.getValues()
Logger.log(source1);
  // get destination range 
  var paste1 = pasteSheet.setRange(pasteSheet.getLastRow()+1,1,1,13); 
    
  // copy values to destination range
  source1.setValues(paste1); 
  // clear source values 
  source1.clearContent(); 
}