Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:44:15+00:00 2026-06-11T23:44:15+00:00

Can the getRange be used to have a named range instead of an area?

  • 0

Can the getRange be used to have a named range instead of an area?
When I seem to do it, it says the argument must be a range.
For example,

Instead of:

     getRange("A4:E7");

The area of A4:E7 has been made into a named range called ‘Names’ in sheet1.

Could you perhaps use:

var tableRange = SpreadsheetApp.getActiveSpreadsheet();.getRangeByName("Names");
getRange(tableRange);

Or is there any other way of doing it. The full code is:

function onEdit(event){
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var editedCell = ss.getActiveCell();

    var columnToSortBy = 1;
    var tableRange = ss.getRangeByName("Names");

    if(editedCell.getColumn() == columnToSortBy){ 
        var range = ss.getRange(tableRange); 
        range.sort( { column : columnToSortBy } );
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:44:16+00:00Added an answer on June 11, 2026 at 11:44 pm

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

    Custom function returning A1 address of named range:

    function myGetRangeByName(n) {  // just a wrapper
      return SpreadsheetApp.getActiveSpreadsheet().getRangeByName(n).getA1Notation();
    }
    

    Then, in a cell on the spreadsheet:

    =myGetRangeByName("Names")
    

    This would put whatever "Names" is defined as into the cell. It will NOT update when you redefine "Names," because of GAS’s aggressive caching. You can, however, force GAS to update it on every sheet calculation.

    =myGetRangeByName("Names",now())
    

    The javascript will ignore the unused parameter.

    The following code does what I think you intend. When the first column of the sheet is edited, it sorts the range based on that column.

    function onEdit(e) {
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var editedCell = ss.getActiveCell();
      var columnToSortBy = 1;
      var tableRange = ss.getRangeByName("Names");
      if ( editedCell.getColumn() == columnToSortBy ) {
        tableRange.sort(columnToSortBy);
      }
    }
    

    This will NOT work if you move the list off column A, because getColumn() returns the absolute column, not the location of the cell in the range. You would have to add code to adjust for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I order my users in the database, so I don't have to say
Can I authenticate with just Google account username and password instead of using OAuth?
Can anyone give me an example of how to return the following json simply
How can we set style to all cells in a range? Rather than this
I have an issue trying to maximize the performance of our listview that has
Can a LINQ enabled app run on a machine that only has the .NET
Can you have submenus with the top level set to checkable in WPF? I
Can't seem to get the Back Button to appear in a UINavigationController flow. I
Can anyone let me know how can we change the value of kendo combobox
Can I change the field public virtual ClassOne ClassOne { get; set; } to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.