'Google Apps Script to import data from another sheet

I want to import a sheet from another Google Spreadsheet only using Google Apps Script.

I also want the script to run every 4 hours so the network is not overloaded.

I have tried using the solution from this thread: How to import a sheet from another Google Spreadsheet using Google Apps Scipt? However, the imported values are not displaying, with most of the columns showing either blanks or #REF errors.

This is the code that I am using:

function CopyDataToNewFile() {
  var sss = SpreadsheetApp.openById('0AjN7uZG....'); // sss = source spreadsheet
  var ss = sss.getSheetByName('Monthly'); // ss = source sheet
  //Get full range of data
  var SRange = ss.getDataRange();
  //get A1 notation identifying the range
  var A1Range = SRange.getA1Notation();
  //get the data values in range
  var SData = SRange.getValues();

  var tss = SpreadsheetApp.openById('8AjN7u....'); // tss = target spreadsheet
  var ts = tss.getSheetByName('RAWData'); // ts = target sheet
  //set the target range to the values of the source data
  ts.getRange(A1Range).setValues(SData);
};


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source