In this example the goal to return the full address of a range or named range as text. For example given the range A1:B10, the result should be "A1:B10". The core of the formula below is the ADDRESS function, which is used to return a cell address based on a given row and column. Unfortunately, the formula gets somewhat complicated because we need to use ADDRESS twice: once to get address of the first cell in the range, and once to get the address of the last cell in the range. The two results are joined with concatenation and the range operator (:) and the full range is returned as text. See below for a more elegant solution in Excel 365.
To get the first cell in the range, we use this formula:
The ROW function returns the first row number associated with the range, 5 and the COLUMN function returns the first column number associated with the range, 2. With abs_num set to 4 (relative), ADDRESS returns the text "B5".
=ADDRESS(5,2,4) // returns "B5"
Note: actually, ROW and COLUMN are returning multiple results, but in Legacy Excel, implicit intersection causes just the first result to used, which works well in the formula. In Excel 365 however, all values are returned and we need to take an extra step to get only the first value. See below.
To get the last cell in the range, we use this formula:
See this page for a detailed explanation. Essentially, we follow the same idea as above, adding simple math to calculate the last row and last column of the range, which are fed as before into ADDRESS with abs_num set to 4. This reduces to the following expression, which returns the text "D10":
=ADDRESS(10,4,4) // returns "D10"
Both results are concatenated with a colon in between to get a final range address as text:
Excel 365 fix
In the formula above, we use implicit intersection to stop the ROW and COLUMN function from returning multiple results for the full range. The @ operator causes ROWS and COLUMNS to return just the first result for the array.
More elegant formula in Excel 365
New array functions in Excel 365 make it possible to solve the problem with a more elegant formula like this:
Here, the LET function is used assign intermediate results to the variable a. Working from the inside out, the ADDRESS function builds an array containing all cell references for all cells in the range or array:
ADDRESS(ROW(rng),COLUMN(rng)) // get all addresses
This result is assigned to the variable a. Next, the TAKE function is used to get the first and last address from a:
TAKE(a,1,1)&":"&TAKE(a,-1,-1) // concatenate first and last
The two address are concatenated with a colon in between to get the final result.
Named range from another cell
To get an address for a named range in another cell, you'll need to use the INDIRECT function. For example, to get the address of a name in A1, you would use:
Set abs_num to 4 inside ADDRESS to get a relative address.
* Actually, in all cases where we use ROW and COLUMN with a multi-cell named range, we'll get back an array of numbers instead of a single value. However, since we aren't using an array formula, processing is limited to the first item in these arrays.