Last active
August 26, 2020 05:33
-
-
Save mogsdad/4661225 to your computer and use it in GitHub Desktop.
In StackOverflow Q14237351 the user wanted to be able to repeat formulas on multiple sheets within their spreadsheet. See http://stackoverflow.com/questions/14237351/how-to-reference-the-current-spreadsheet-in-a-named-range-in-google-spreadsheets/14287340#14287340.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return a string with the A1 notation for the given range, with | |
* the sheet reference removed. To use in spreadsheet functions, | |
* enclose with INDIRECT(). | |
* | |
* Example: | |
* =index(INDIRECT(localizeNamedRange(NamedRange1)),12,4) | |
* | |
* @param {string} rangeName The name of an existing range in the | |
* active spreadsheet. It does not matter which | |
* sheet the range was defined for. | |
* | |
* @return {string} The cell range from the provided rangeName, | |
* in A1 notation. | |
*/ | |
function localizeNamedRange( rangeName ) { | |
var sheet = SpreadsheetApp.getActiveSpreadsheet(); | |
// Get range by name | |
var origRange = sheet.getRangeByName(rangeName); | |
// Get notation for the range, without sheet reference. | |
var notation = ""; | |
if (origRange !== null) { | |
notation = origRange.getA1Notation(); | |
} | |
// Return range in A1 notation | |
debugger; // pause to examine if running in debugger | |
return ( notation ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment