Google Sheets – How to Create Named Ranges Based on Formulas

google sheets

I have a list of items (cells A1 to A7) that are counted in cell B2 (whose value is currently 7), B2's formula is something like =COUNTA(A1:A10000).
That way if I add some value in cell A8, the count is updated to 8 in cell B2. And so on and so forth when values are filled in cells A9, A10, … etc, the count in cell B2 always keeps track of the current number of items in the list.

It would be very handy to have the ability of creating a named range, called items for instance, based on the count in cell B2 using

=OFFSET(sheet!$A$1,0,0,sheet!$B$2,1)

or

=ArrayFormula(OFFSET(sheet!$A$1,0,0,sheet!$B$2,1))

to define the named range.

That way items could be used anywhere and would get dynamically updated when the item list is modified.

This is the way it can be done in Excel, but what would be the corresponding approach using Google Sheets?

Best Answer

  1. You could use a simple formula to build a string defining the Range, name that location, and then access it with the INDIRECT Function in your formulas. E.g. for your question above.

    Put in any cell (e.g. B3) a formula like:

    = "Sheet!$A$1:$A$" & B2
    
  2. Name Cell B3 as "items" as a named range.

  3. Then whenever you would have used "items" in a formula just use

    INDIRECT(items)
    

It is not quite the same as a dynamic named range, but almost as neat and certainly as effective.