Unique Dynamic Range

jbeaucaire

Well-known Member
Joined
May 8, 2002
Messages
6,012
In the table shown below, the "AA" and "BB" and "CC" (etc) can really occur anywhere in the table. The full range of the table is actually B28:Y96.

I'm trying to count the number of "w" entries that appear in the randomly places "AA" section, in the example it resolves to B29:D32.

I'd like a dynamic range formula I could use to:

1) Spot the location of "AA"
2) Create a search range of the 12 cells offset below them as shown
3) Count the "w" entries in that dynamically located region

I'm stumped.

Excel Workbook
ABCDEFGHIJKLM
27
286AA3CC0WWm0YYm
29Bowler 112.1..
303bw...2
31wides
32no balls
33163063000000
34
352BB5DD0XXm0ZZm
36Bowler 2...12.
37....w2lb
38wides1
39no balls1
40082163000000
41
427EE8GG0m0m
43Bowler 31..6..
4424.1lb1bw
45wides
46no balls
47067166000000
48
Score Book
Cells with Conditional Formatting
CellConditionCell FormatStop If True
The Results will go into this table:

Excel Workbook
AOAPAQARAS
28OverRunsWktsTotal
291AA616
302BB208
313CC3011
324DD5116
335EE7023
346FF0023
357GG8131
Score Book
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Additional note... I could make short work of this with VBA, but it's a formula based solution (dynamic named range would be ideal) that I'm searching for. The project is VBA free so far.
 
Upvote 0
Additional note... I could make short work of this with VBA, but it's a formula based solution (dynamic named range would be ideal) that I'm searching for. The project is VBA free so far.
If I understand the requirements...

=OFFSET(B28,MAX(IF(B28:Y96="AA",ROW(B28:Y96)))-ROW(B28)+1,MAX(IF(B28:Y96="AA",COLUMN(B28:Y96)))-COLUMN(B28)+1-2,4,3)

Creating the named range:

Name: MyRange
Refers to:

=OFFSET($B$28,MAX(IF($B$28:$Y$96="AA",ROW($B$28:$Y$96)))-ROW($B$28)+1,MAX(IF($B$28:$Y$96="AA",COLUMN($B$28:$Y$96)))-COLUMN($B$28)+1-2,4,3)

Book1
ABCDE
30__AA__
31WW_WW
32_____
33_____
34WW_WW
35_W_W_
Sheet1

=COUNTIF(MyRange,"w")

=4
 
Upvote 0
I also use a named approach.

Select a cell in row 29 and define

Name: MatchColumn RefersTo: =SUMPRODUCT(--(Sheet1!$A$1:$M$100=Sheet1!$AP29)*COLUMN(Sheet1!$A$1:$M$100))

Name: MatchRow RefersTo: =SUMPRODUCT(--(Sheet1!$A$1:$M$100=Sheet1!$AP29)*ROW(Sheet1!$A$1:$M$100))


Then put =OFFSET($A$1, matchRow-1, matchColumn-2) in AQ29
and =OFFSET($A$1, matchRow+4, matchColumn-2) in AR29
and =SUM(AQ$29:AQ29) in AS29
and drag down.

Handling the #REF error in the (non-existent) FF case can be done variously.

<table border=1 cellspacing=0>
<tr align="center" bgcolor=#A0A0A0><td width=25> <td width=25><b>AP</b><td width=25><b>AQ</b><td width=25><b>AR</b><td width=25><b>AS</b></tr>
<tr><td align="center" bgcolor=#A0A0A0><b>28</b><td align="left" bgcolor=#FFFFFF><td align="left" bgcolor=#FFFFFF>Runs<td align="left" bgcolor=#FFFFFF>Wkts<td align="left" bgcolor=#FFFFFF>Total</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>29</b><td align="left" bgcolor=#FFFFFF>AA<td align="right" bgcolor=#FFFFFF>6<td align="right" bgcolor=#FFFFFF>1<td align="right" bgcolor=#FFFFFF>6</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>30</b><td align="left" bgcolor=#FFFFFF>BB<td align="right" bgcolor=#FFFFFF>2<td align="right" bgcolor=#FFFFFF>0<td align="right" bgcolor=#FFFFFF>8</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>31</b><td align="left" bgcolor=#FFFFFF>CC<td align="right" bgcolor=#FFFFFF>3<td align="right" bgcolor=#FFFFFF>0<td align="right" bgcolor=#FFFFFF>11</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>32</b><td align="left" bgcolor=#FFFFFF>DD<td align="right" bgcolor=#FFFFFF>5<td align="right" bgcolor=#FFFFFF>1<td align="right" bgcolor=#FFFFFF>16</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>33</b><td align="left" bgcolor=#FFFFFF>EE<td align="right" bgcolor=#FFFFFF>7<td align="right" bgcolor=#FFFFFF>0<td align="right" bgcolor=#FFFFFF>23</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>34</b><td align="left" bgcolor=#FFFFFF>FF<td align="left" bgcolor=#FFFFFF>#REF!<td align="left" bgcolor=#FFFFFF>#REF!<td align="left" bgcolor=#FFFFFF>#REF!</tr>
<tr><td align="center" bgcolor=#A0A0A0><b>35</b><td align="left" bgcolor=#FFFFFF>GG<td align="right" bgcolor=#FFFFFF>8<td align="right" bgcolor=#FFFFFF>1<td align="left" bgcolor=#FFFFFF>#REF!</tr>
</table>
 
Upvote 0
Here's a similar approach...

1) Select AR29

2) Define the following...

Name: Pos

Refers to:

=SMALL(IF($B$28:$M$47=$AP29,(ROW($B$28:$M$47)-ROW($B$28)+1)*10^5+(COLUMN($B$28:$M$47)-COLUMN($B$28)+1)),1)

Name: MyRange

Refers to:

=OFFSET(Sheet1!$B$28,LEFT(Pos,LEN(Pos)-5),RIGHT(Pos,5)-2,4,3)

3) Then try the following formula...

AR29, copied down:

=IFERROR(COUNTIF(MyRange,"w"),0)

or

=IF(COUNTIF($B$28:$M$47,$AP29)>0,COUNTIF(MyRange,"w"),0)
 
Upvote 0
Thanks all, I just got back from church... will try these out and report back. Thank you all!
 
Upvote 0
Well, I feel like a ditz. Turns out the owner of the sheet had already done the heavy-lifting on the sheet for counting the "w" entries in each section and placed in the cell OFFSET(5, -1) from where the "AA" was randomly found. I am sorry I didn't notice that earlier, because that allows a simple SUMIF() with offset ranges do the final work:

Excel Workbook
AOAPAQARAS
28OverRunsWktsTotal
291AA616
302BB218
313CC3111
324DD5216
335EE7223
346FF0223
357GG8331
368HH0331
379II0331
3810JJ0331
Score Book




Thanks for the ideas, though, this has actually been helpful, some interesting approaches to the Named Range feat. I will file away these examples for reference later. Thanks again for taking the time!
 
Upvote 0
Well, I feel like a ditz. Turns out the owner of the sheet had already done the heavy-lifting on the sheet for counting the "w" entries in each section and placed in the cell OFFSET(5, -1) from where the "AA" was randomly found. I am sorry I didn't notice that earlier, because that allows a simple SUMIF() with offset ranges do the final work:

Excel Workbook
AOAPAQARAS
28OverRunsWktsTotal
291AA616
302BB218
313CC3111
324DD5216
335EE7223
346FF0223
357GG8331
368HH0331
379II0331
3810JJ0331
Score Book




Thanks for the ideas, though, this has actually been helpful, some interesting approaches to the Named Range feat. I will file away these examples for reference later. Thanks again for taking the time!
Good deal. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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