Linked dynamic named ranges - unexpected results.

Ramses505

New Member
Joined
Oct 17, 2016
Messages
37
Office Version
  1. 2010
Platform
  1. Windows
I have recently come across some code to create a 'Dynamic' Named Range - this is really useful and I wish I had discovered it earlier :)
The code is like this
VBA Code:
ActiveWorkbook.Names.Add Name:="Date", RefersTo:="=$B$3:INDEX($B:$B, COUNTA($B:$B)+3)"

This is operating on a column of dates where every row has a date (starting in Row 3), so works great. I have other Named Ranges which cover columns of non continous Row Data - there can (have to be) blanks. I have tried this code for another Named Range called 'Value' like this;
VBA Code:
ActiveWorkbook.Names.Add Name:="Value", RefersTo:="=$C$3:INDEX($C:$C, COUNTA($B:$B)+3)"

This works but the Named Range 'Value' seems to have an extra Row in it !

If some DATA looks like this;
B C
1 1
1 1
1 1
1 1
1

The formula '=SUM(Date)' (in, say, E1) yields '4' and 'SUM(Value)' (in, say, F1) yields '5' - which is obviously wrong. If I add further rows to Col B and some extra data to Col C - the dynamic named range 'Date' expands as expected but the dynamic named range 'Value' always seems to contain 1 extra row.

By adjusting the formula for 'Value' to; =$C$3:INDEX($C:$C, COUNTA($B:$B)+2) (Note the +2 instead of +3) everything works as I would expect it to, which is good.

What am I not understanding about what is happening here. Why does the 'Value' formula need to be different ?

Thanks for any help.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello!
Not very strong, but shouldn’t Value have COUNTA($С:$С), instead of what you have COUNTA($B:$B)
 
Upvote 0
Hello!
Not very strong, but shouldn’t Value have COUNTA($С:$С), instead of what you have COUNTA($B:$B)
OK, maybe I wasn't quite clear. The point of using 'COUNTA($B:$B)' instead of 'C' is so that the second named range (the one with blanks in it) uses the same number of rows as the dynamic named range which does not have blanks. Does that make more sense ? Thanks
 
Upvote 0

Forum statistics

Threads
1,222,761
Messages
6,168,055
Members
452,160
Latest member
Bekerinik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top