Dynamic Named Range

scott_od

New Member
Joined
Jan 25, 2016
Messages
13
Hi, I have an excel workbook with 2 worksheets.

The first worksheet called "Data" contains a list of places & some corresponding numbers - this data changes every month & the number of entries per location varies from month to month (for example, this month there are 5 x Rotterdam, 7 x Liverpool and 15 x Rome, however next month it could be 2 x Rotterdam, 15 x Liverpool and 8 x Rome).

Code:
[B]Excel 2012[/B][TABLE]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH][/TH]
[TH]A[/TH]
[TH]B[/TH]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]Place[/TD]
[TD="bgcolor: #92D050, align: center"]#'s[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]Rotterdam[/TD]
[TD="align: center"]21[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]Rotterdam[/TD]
[TD="align: center"]27[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD]Rotterdam[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD]Rotterdam[/TD]
[TD="align: center"]27[/TD]
[/TR]
[TR]
[TD="align: center"]6[/TD]
[TD]Rotterdam[/TD]
[TD="align: center"]28[/TD]
[/TR]
[TR]
[TD="align: center"]7[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]8[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]9[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]10[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]11[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]12[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]13[/TD]
[TD]Liverpool[/TD]
[TD="align: center"]26[/TD]
[/TR]
[TR]
[TD="align: center"]14[/TD]
[TD]Rome[/TD]
[TD="align: center"]20[/TD]
[/TR]
[TR]
[TD="align: center"]15[/TD]
[TD]Rome[/TD]
[TD="align: center"]18[/TD]
[/TR]
[TR]
[TD="align: center"]16[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
[TR]
[TD="align: center"]17[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
[TR]
[TD="align: center"]18[/TD]
[TD]Rome[/TD]
[TD="align: center"]18[/TD]
[/TR]
[TR]
[TD="align: center"]19[/TD]
[TD]Rome[/TD]
[TD="align: center"]18[/TD]
[/TR]
[TR]
[TD="align: center"]20[/TD]
[TD]Rome[/TD]
[TD="align: center"]20[/TD]
[/TR]
[TR]
[TD="align: center"]21[/TD]
[TD]Rome[/TD]
[TD="align: center"]18[/TD]
[/TR]
[TR]
[TD="align: center"]22[/TD]
[TD]Rome[/TD]
[TD="align: center"]20[/TD]
[/TR]
[TR]
[TD="align: center"]23[/TD]
[TD]Rome[/TD]
[TD="align: center"]20[/TD]
[/TR]
[TR]
[TD="align: center"]24[/TD]
[TD]Rome[/TD]
[TD="align: center"]18[/TD]
[/TR]
[TR]
[TD="align: center"]25[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
[TR]
[TD="align: center"]26[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
[TR]
[TD="align: center"]27[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
[TR]
[TD="align: center"]28[/TD]
[TD]Rome[/TD]
[TD="align: center"]22[/TD]
[/TR]
</tbody>[/TABLE]
[CENTER][COLOR=#161120][B]Data[/B][/COLOR][/CENTER]

The second worksheet is called "Liverpool" and contains a graph with the corresponding numbers for Liverpool.
It also includes some formulas that quickly show me which rows/data range are related to Liverpool, as this varies every month.

For the sake of transparency I have removed the "=" from the formulas so you can see how they are calculated, but the result of the formula in cell I4 is "Data!B7:Data!B13" which is the range for data related to Liverpool which is needed for the graph.

Code:
[B]Excel 2012[/B][TABLE]
<tbody>[TR="bgcolor: #DAE7F5"]
[TH][/TH]
[TH]H[/TH]
[TH]I[/TH]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="bgcolor: #D6DCE4"]Liverpool[/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]MATCH(H1,Data!$A$1:Data!$A$412,0)[/TD]
[TD]"Data!B"&CONCATENATE(H2)[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD]MAX(ROW(Data!$1:$412)*(Data!$A$1:$A$412=H1))[/TD]
[TD]":Data!B"&CONCATENATE(H3)[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD]CONCATENATE(I2,I3)[/TD]
[/TR]
</tbody>[/TABLE]
[CENTER][COLOR=#161120][B]Liverpool[/B][/COLOR][/CENTER]
*note the formula in H3 is an array formula.

What I would like to do is use the value in cell I4 as the range for the graph. I believe I cannot do this directly, but must create a named range, but I am also struggling to make this work.

Can anyone help?
 

Some videos you may like

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Because your data is sorted you can use dynamic names like:

LiverpoolX =OFFSET(Data!$A$1,MATCH(Liverpool!$H$1,Data!$A:$A,0)-1,0,COUNTIF(Data!$A:$A,Liverpool!$H$1))
LiverpoolY =OFFSET(LiverpoolX,0,1)
 

scott_od

New Member
Joined
Jan 25, 2016
Messages
13
Andrew thanks so much, I really appreciate that.
It works fine - I don't full understand it yet, but it works :)

One more question: What if this was the data set & I wanted separate named ranges for Liverpool via London and Liverpool via St Albans

Code:
<b>Excel 2012</b><table cellpadding="2.5px" rules="all" style=";background-color: #FFFFFF;border: 1px solid;border-collapse: collapse; border-color: #BBB"><colgroup><col width="25px" style="background-color: #DAE7F5" /><col /><col /><col /></colgroup><thead><tr style=" background-color: #DAE7F5;text-align: center;color: #161120"><th></th><th>A</th><th>B</th><th>C</th></tr></thead><tbody><tr ><td style="color: #161120;text-align: center;">1</td><td style="font-weight: bold;;">Place</td><td style="font-weight: bold;;">Via</td><td style="font-weight: bold;text-align: center;color: #FFFFFF;background-color: #92D050;;">#'s</td></tr><tr ><td style="color: #161120;text-align: center;">2</td><td style=";">Rotterdam</td><td style=";">Den Haag</td><td style="text-align: center;;">21</td></tr><tr ><td style="color: #161120;text-align: center;">3</td><td style=";">Rotterdam</td><td style=";">Den Haag</td><td style="text-align: center;;">27</td></tr><tr ><td style="color: #161120;text-align: center;">4</td><td style=";">Rotterdam</td><td style=";">Den Haag</td><td style="text-align: center;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">5</td><td style=";">Rotterdam</td><td style=";">Den Haag</td><td style="text-align: center;;">27</td></tr><tr ><td style="color: #161120;text-align: center;">6</td><td style=";">Rotterdam</td><td style=";">Den Haag</td><td style="text-align: center;;">28</td></tr><tr ><td style="color: #161120;text-align: center;">7</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">London</td><td style="text-align: center;color: #FF0000;;">15</td></tr><tr ><td style="color: #161120;text-align: center;">8</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">London</td><td style="text-align: center;color: #FF0000;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">9</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">London</td><td style="text-align: center;color: #FF0000;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">10</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">St Albans</td><td style="text-align: center;color: #FF0000;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">11</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">St Albans</td><td style="text-align: center;color: #FF0000;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">12</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">St Albans</td><td style="text-align: center;color: #FF0000;;">26</td></tr><tr ><td style="color: #161120;text-align: center;">13</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">St Albans</td><td style="text-align: center;color: #FF0000;;">30</td></tr><tr ><td style="color: #161120;text-align: center;">14</td><td style="color: #FF0000;;">Liverpool</td><td style="color: #FF0000;;">St Albans</td><td style="text-align: center;color: #FF0000;;">7</td></tr><tr ><td style="color: #161120;text-align: center;">15</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">20</td></tr><tr ><td style="color: #161120;text-align: center;">16</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">18</td></tr><tr ><td style="color: #161120;text-align: center;">17</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr><tr ><td style="color: #161120;text-align: center;">18</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr><tr ><td style="color: #161120;text-align: center;">19</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">18</td></tr><tr ><td style="color: #161120;text-align: center;">20</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">18</td></tr><tr ><td style="color: #161120;text-align: center;">21</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">20</td></tr><tr ><td style="color: #161120;text-align: center;">22</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">18</td></tr><tr ><td style="color: #161120;text-align: center;">23</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">20</td></tr><tr ><td style="color: #161120;text-align: center;">24</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">20</td></tr><tr ><td style="color: #161120;text-align: center;">25</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">18</td></tr><tr ><td style="color: #161120;text-align: center;">26</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr><tr ><td style="color: #161120;text-align: center;">27</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr><tr ><td style="color: #161120;text-align: center;">28</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr><tr ><td style="color: #161120;text-align: center;">29</td><td style=";">Rome</td><td style=";">Milan</td><td style="text-align: center;;">22</td></tr></tbody></table><p style="width:2.4em;font-weight:bold;margin:0;padding:0.2em 0.6em 0.2em 0.5em;border: 1px solid #BBB;border-top:none;text-align: center;background-color: #DAE7F5;color: #161120">Data</p><br /><br />
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
With the Via location in H2:

=OFFSET(Data!$A$1,MATCH(1,INDEX((Data!$A:$A=Liverpool!$H$1)*(Data!$B:$B=Liverpool!$H$2),),0)-1,0,COUNTIFS(Data!$A:$A,Liverpool!$H$1,Data!$B:$B,Liverpool!$H$2))
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,610
Members
414,080
Latest member
penguin23

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
Top