I have 4 sheets. Form, Raw, URL and USA/Japan/Canada. I get the spreadsheet url value from the URL sheet and use 'IMPORTRANGE' in the Raw sheet to transfer the data table. From there, i loop through the table in Raw sheet to check if the values is match from the values in the Form sheet. If it's matched, i will transfer that row in the USA/Japan/Canada sheet.
So i got this code in my google sheets:
var mainWS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Form');
var continentWS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('USA/Japan/Canada');
var rawWS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Raw');
var urlWS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('URLs');
var tourName = mainWS.getRange('C4').getValue();
var depDate = new Date(mainWS.getRange('C5').getValue());
var status = mainWS.getRange('C6').getValue();
//extract table data
var url = urlWS.getRange("B4").getValue();
rawWS.getRange('A1').setValue('=IMPORTRANGE("' + url + '","Main Data!A1:AE")');
var dummyHolder = rawWS.getRange("B1:B").getValues();
var lastRow = dummyHolder.filter(String).length;
Logger.log(lastRow);
//loop through the raw extract
for(var i = 2; i <= lastRow; i++){
var dateHolder = new Date(rawWS.getRange("E" + i).getValue());
if(rawWS.getRange("F" + i).getValue() == tourName && rawWS.getRange("I" + i).getValue() == status && dateHolder.getTime() === depDate.getTime()){
var continentLR = continentWS.getLastRow() + 1;
rawWS.getRange('Raw!' + i + ':' + i + '').copyTo(continentWS.getRange(continentLR, 1), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
}
}
Then i suddenly get the "The coordinates of the target range are outside the dimensions of the sheet" error message once it enters the loop. Specifically in the first line after the for loop:
var dateHolder = new Date(rawWS.getRange("E" + i).getValue());
To be clear, the rawWS where it is looping has 134 records and it registers 134 as its last row. I don't know why i am getting an error here.
When i remove that line, it still gives me an error on the next line. It all errors inside the for loop.
Any ideas?