0

I need order by alphabet a list in a range by name, but for some reason fail in some point and give me a "The cell reference is out of range." in line var tmp_range = raw_range.sort( 1 );

The weird think is in the first call seems to work but with the sencond call (with other range name) fail.

function getValuesOfRange( range_name ){
  var raw_range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName( range_name );
  Logger.log( raw_range );
  if ( raw_range != null ){
    Logger.log( range_name );
    var tmp_range = raw_range.sort( 1 );
  }
  ...
}

1 Answer 1

1

The most probable cause is you are providing wrong index inside the parameter. The sort function takes different types of argument. Check here

https://developers.google.com/apps-script/reference/spreadsheet/range#sortsortspecobj

// Sorts by the values in the first column (A)
 range.sort(1);

So for example if your named range is from 'Sheet1'!D1:D9 The sorting should be like range.sort(4);

So in your case change raw_range.sort( 1 ) to raw_range.sort( raw_range.getColumn())

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

2 Comments

Thx. I change raw_range.sort( 1 ) by raw_range.sort( raw_range.getColumn() ) and work perfect. Can you edit your answer with this code to mark as correct answer?
Updated the anwser

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.