1

I have a simple script that copies value from one sheet and pastes into another, however it takes 10+ mins every single time.

There are about 100K rows in the file. i have tried even separating them out but makes no difference.

function makeDataCopies()
{
  Logger.log("starts");
  var copyTo = DEST.getSheetByName(WSHEET);
  var copyFrom = SOURCE.getSheetByName(WSHEET);
  
  var copyArray = copyFrom.getDataRange().getValues();
 
  Logger.log("calls copy");
  copyTo.getRange(1,1,copyArray.length,copyArray[0].length).setValues(copyArray);

}

1 Answer 1

0

I believe your goal as follows.

  • You want to reduce the process cost of your script.

I thought that from your situation of There are about 100K rows in the file., I would like to propose to use Sheets API for your situation. When Sheets API is used, the process cost can be reduced from Google Spreadsheet service of SpreadsheetApp. Ref

When your script is modified using Sheets API, it becomes as follows.

Modified script:

Before you use this script, please enable Sheets API at Advanced Google services.

function makeDataCopies() {
  var dstSpreadsheetId = "###"; // Please set the destination Spreadsheet ID.
  var srcSpreadsheetId = "###"; // Please set the source Spreadsheet ID.
  var WSHEET = "###"; // Please set the sheet name.

  var srcValues = Sheets.Spreadsheets.Values.get(srcSpreadsheetId, WSHEET).values;
  Sheets.Spreadsheets.Values.update({values: srcValues}, dstSpreadsheetId, WSHEET, {valueInputOption: "USER_ENTERED"});
}

References:

3
  • @KES Thank you for replying. I'm glad your issue was resolved.
    – Tanaike
    Apr 29, 2021 at 1:01
  • now i am having issues with date fields. they are getting all messed up. i have tried both RAW and USER_ENTERED, each have their own issues. how could i overcome that?
    – KES
    Apr 29, 2021 at 14:01
  • @KES Thank you for replying. About your new question, I would like to support you. But I have to apologize for my poor English skill. Unfortunately, from now i am having issues with date fields. they are getting all messed up. i have tried both RAW and USER_ENTERED, each have their own issues., I cannot understand about your situation. So, in order to correctly understand about it, by including more information, can you post it as new question? By this, it will help users including me think of the solution. When you can cooperate to resolve your issue, I'm glad. Can you cooperate to do it?
    – Tanaike
    Apr 29, 2021 at 23:31

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.