0

I'm trying to copy sheets from what I'm calling a "Master" workbook to a workbook that my staff has access to but I can't seem to get it to copy.

Once I have the script, I'm going to set it up to copy every day. That way I can edit the Master and it will essentially "auto update" for my staff every day.

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');

var targetSheet = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g').getSheetByName('General');

sourceSheet.copyTo(targetSheet);
}

It just tells me there's an error:

Error
Exception: The parameters (number,number,number,null) don't match the method signature for SpreadsheetApp.Sheet.getRange. copyDoc @ Test Copy.gs:11

I have absolutely no idea what I'm doing or what I should be doing. Essentially I need to copy Sheet 1 through 7 from Workbook A into Sheet 1 through 7 of Workbook B every single day. But the sheets are all already in each Workbook and titled.

Screenshot

Rubén
  • 34,714
  • 9
  • 70
  • 166
Marisa
  • 1
  • 2
  • Yes that function just copies the entire sheet to another spreadsheet and gives it unique name and it returns the sheet object so that you can then copy the data from it to other sheets and then you can delete it when you are through. – Cooper Mar 24 '22 at 20:00
  • You can copy a 2d array from one spreadsheet to another but then you lose all of your formatting. – Cooper Mar 24 '22 at 20:03
  • Apparently you have some idea as you were able to run the code. Besides the code as text that you already included add a screenshot of the Google Apps Script tab from where you are running the code. – Rubén Mar 24 '22 at 20:55

2 Answers2

0

The screenshot shows that your project has 4 files.

The file having the function that you are trying to execute is in file Copy Daily.gs. This file has only 7 lines. The error doesn't belong to that file (as explained below).

  1. Test Copy.gs is the file name having the statement causing the error.
  2. 11 is the line number of the Test Copy.gs file.
  3. getRange is the method having the problem

It's very likely that the error is occurring because the referred line from file Test Copy.gs is in the global scope. Statements in the global scope, no matter on which file they are, are executed before executing the function called.

Possible fix:

  1. Open the Test Copy.gs file
  2. Add // at the beginning of line 11

Another option is to delete the Test Copy.gs file. If you have valuable information on that file, before deleting it, make an appropriate backup.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166
0

I asked on Reddit and this ended up working!

function copyDoc() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('General');
var target = SpreadsheetApp.openById('13ERWTQoXeGb0cIfgfr2ZTsImnwmtaVB5c-Zm9ZZ5o6g');
sourceSheet.copyTo(target);
target.deleteSheet(target.getSheetByName("General"));
var targetSheet = target.getSheetByName("Copy of General")
target.setActiveSheet(targetSheet)
target.moveActiveSheet(1);
targetSheet.setName("General");
}

I then just copied and pasted it and changed the name of the sheets for it work across all of the sheets I have in one document.

Marisa
  • 1
  • 2