Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
488 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Dynamic range names |
---|
Creating named ranges in Excel can make your formulas much easier to create and read, and we encourage people to use them often. Range names do have one big limitation, however: they don't automatically expand if you add new data to the worksheet. This blog shows you a couple of ways to create dynamic range names to get around this problem. |
In this blog
Using range names is a great way to make your Excel formulas easy to write and read (see this blog or this video if you'd like to learn how to create named ranges).
This formula uses two range names to calculate the Profit for a list of films.
Entering the formula shown above creates a spilled array, calculating an answer for each row of the input ranges.
The array of answers spills into the neighbouring cells.
Unfortunately, a range name doesn't automatically expand to include new data added next to it.
Simply adding new data to the end of each range doesn't work.
You could force a range name to expand by inserting a new row between the top and bottom of the range.
We could make the range names reference all the cells we may potentially add data to in the future, but this causes its own problem:
Excel calculates a result even if the range names refer to empty cells.
We'd like to make each range name dynamically change its size when data is added to the worksheet. To do this, we need to create a formula to return the range of populated cells and assign it to the range name. Start by choosing Formulas | Name Manager from the Excel ribbon.
Select a range name from the list then edit its formula in the Refers to: box.
There are two main ways to write the formula to create a dynamic range name, as detailed below:
If you're working with an older version of Excel, you can use a combination of the OFFSET and COUNTA functions.
The COUNTA function counts the non-blank cells in a range. In the example below, we're counting the non-blank cells in column B (excluding cell B1):
There are 3 non-blank cells below B1 in this worksheet.
The OFFSET function allows you to point to a starting cell, move a number of rows and columns away from that cell, and return a range of cells with a specified height and width. Here's the syntax of the function:
=OFFSET(Starting cell, Rows to move down, Columns to move right, Number of rows to include, Number of columns to include)
To create a dynamic range which includes all the Gross numbers, we want to:
Start in cell B2.
Move 0 rows down.
Move 0 columns to the right.
Include a number of rows equal to the count of non-blank cells in the column (excluding B1).
Include 1 column.
Here's a formula to return the range of Gross numbers:
=OFFSET(Sheet1!$B$2, 0, 0, COUNTA(Sheet1!$B$2:$B$1048576), 1)
We can assign this formula to the Gross range name using the Name Manager:
Enter the formula in the Refers to: box and click the tick to commit it.
We can do the same thing for the Budget range name using the following formula:
=OFFSET(Sheet1!$C$2, 0, 0, COUNTA(Sheet1!$C$2:$C$1048576), 1)
If you're using an up-to-date version of Excel, you can use the TRIMRANGE function to make the calculation simpler. The TRIMRANGE function allows you to reference a large range of cells and ignore the blanks (you can read more about the function in this blog).
The formula for the Gross range name is:
=TRIMRANGE(Sheet1!$B$2:$B$1048576)
The formula for the Budget range name is:
=TRIMRANGE(Sheet1!$C$2:$C$1048576)
You can make the formula even shorter by using a Trim Ref instead of the TRIMRANGE function. To do this, place a full stop on each side of the colon in the cell reference. Here's the formula for the Gross range name:
=Sheet1!$B$2.:.$B$1048576
Whichever style of formula you use, you should find that the range names will automatically grow and shrink as you add or remove data.
The formula calculates a value for each populated cell in each range.
Some other pages relevant to the above blog include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2025. All Rights Reserved.