1

I'm importing data from one sheet to another sheet using Google Appscript. However when I run the code there's an error occuring.

function importdata() {
    var mainfile = SpreadsheetApp.getActive().getSheetByName('Data1');
    var secondfile = SpreadsheetApp.openById('1232131231231abcc').getSheetByName('RAW');
    var datas = secondfile.getRange('C:C').getValues();
    var paste = mainfile.getRange('A:A').setValues(datas);
}

Message details

Exception: The number of rows in the data does not match the number of rows in the range. The data has 27441 but the range has 27509. (line 6, file "Code")

1 Answer 1

4

setValues expects your range to have the same length as the length of data you are trying to set (must match dimensions of your range).

try something like

var datas = mainfile.getRange('A:A').getValues()

var range = secondfile.getRange(1,1,datas.length);
range.setValues(datas);

Update: I actually think you might have "hidden" rows in your dataset, this might cause range to be confused with length.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, check the udpate, please, if you have hidden rows - they were causing the issue, thus they are not copied to your second file if you use this method. Unhide them first.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.