Using INDEX with non-contiguous ranges

HighAndWilder

Well-known Member
Joined
Nov 4, 2006
Messages
712
Office Version
  1. 365
Platform
  1. Windows
I'd like to be able to use INDEX with non-contiguous ranges.

In this example I would like the formula to return 17 but it returns 10.

Maybe the question should be, how can I return 17 from the two non-contiguous ranges when I know the row and column numbers.

The numbers will not always be unique.

I have not come across this kind of range reference before.

Thanks for any pointers in the right direction.

Version 2.xlsm
ABCDEFGHI
1
21234567
3891011121314
415161718192021
5
6
722232425262728
8
929303132333435
10
1110
12
NCR
Cell Formulas
RangeFormula
B11B11=INDEX($B$2:$H$2:$B$4:$H$4:$B$7:$H$7:$B$9:$H$9,2,3)
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I've missed that detail. Can add an additional condition to filter out that row.
Book1
BCDEFGH
1
21234567
3891011121314
415161718192021
5
6
722232425262728
8
929303132333435
10
11RowColReturn
12111
13122
14133
15144
16155
17166
18177
192115
202216
212317
222418
232519
242620
252721
263122
273223
283324
293425
303526
313627
323728
334129
344230
354331
364432
374533
384634
394735
Sheet3
Cell Formulas
RangeFormula
B12:B39B12=ROUNDUP(SEQUENCE(28)/7,0)
D12:D39D12=INDEX(FILTER($B$2:$H$9,BYROW($B$2:$H$9<>"",OR)*(SEQUENCE(ROWS($B$2:$H$9))<>2)),B12,C12)
Dynamic array formulas.
 
Upvote 0
Can add an additional condition to filter out that row.
It does depend a bit on how the OP want to refer to the different ranges (would be good to get some feedback @HighAndWilder as I have noticed you on the forum a few times since suggestions have been made :)) but I see that method as not very flexible. For example in the sheet below, I have your formulas in column D and the formulas from posts 3 and 4 (adapted to your results layout) in E & F.

24 12 15.xlsm
BCDEFGH
1
21234567
3891011121314
415161718192021
5
6
722232425262728
8
929303132333435
10
11RowColReturnPost 3Post 4
1211111
1312222
1413333
1514444
1615555
1716666
1817777
1921151515
2022161616
2123171717
2224181818
2325191919
2426202020
2527212121
2631222222
2732232323
2833242424
2934252525
3035262626
3136272727
3237282828
3341292929
3442303030
3543313131
3644323232
3745333333
3846343434
3947353535
Disjoint ranges (3)
Cell Formulas
RangeFormula
D12:D39D12=INDEX(FILTER($B$2:$H$9,BYROW($B$2:$H$9<>"",OR)*(SEQUENCE(ROWS($B$2:$H$9))<>2)),B12,C12)
E12:E39E12=INDEX(VSTACK(B$2:H$2,B$4:H$4,B$7:H$7,B$9:H$9),B12,C12)
F12:F39F12=INDEX((B$2:H$2,B$4:H$4,B$7:H$7,B$9:H$9),1,C12,B12)


That's fine, but not only are the earlier ones considerably shorter, they also automatically adapt if further rows are inserted for example whereas your may require a physical change to the formula, depending on where inserted.

24 12 15.xlsm
BCDEFGH
1
21234567
3
4891011121314
515161718192021
6
7
822232425262728
9
1029303132333435
11
12RowColReturnPost 3Post 4
1311111
1412222
1513333
1614444
1715555
1816666
1917777
202181515
212291616
2223101717
2324111818
2425121919
2526132020
2627142121
2731152222
2832162323
2933172424
3034182525
3135192626
3236202727
3337212828
3441222929
3542233030
3643243131
3744253232
3845263333
3946273434
4047283535
Disjoint ranges (3)
Cell Formulas
RangeFormula
D13:D40D13=INDEX(FILTER($B$2:$H$10,BYROW($B$2:$H$10<>"",OR)*(SEQUENCE(ROWS($B$2:$H$10))<>2)),B13,C13)
E13:E40E13=INDEX(VSTACK(B$2:H$2,B$5:H$5,B$8:H$8,B$10:H$10),B13,C13)
F13:F40F13=INDEX((B$2:H$2,B$5:H$5,B$8:H$8,B$10:H$10),1,C13,B13)


It may not be at all relevant to this thread but another advantage of the formulas that directly address the ranges of interest is that it does not matter if those ranges are moved out of physical alignment.

24 12 15.xlsm
BCDEFGHIJKLMNOP
1
21234567
3891011121314
4
515161718192021
6
722232425262728
8
929303132333435
10
11RowColReturnPost 3Post 4
1211111
1312222
1413333
1514444
1615555
1716666
1817777
1921221515
2022231616
2123241717
2224251818
2325261919
2426272020
2527282121
263102222
273202323
283302424
293402525
303502626
3136292727
3237302828
3341#REF!2929
3442#REF!3030
3543#REF!3131
3644#REF!3232
3745#REF!3333
3846#REF!3434
3947#REF!3535
Disjoint ranges (4)
Cell Formulas
RangeFormula
D12:D39D12=INDEX(FILTER($B$2:$H$9,BYROW($B$2:$H$9<>"",OR)*(SEQUENCE(ROWS($B$2:$H$9))<>2)),B12,C12)
E12:E39E12=INDEX(VSTACK(B$2:H$2,J$5:P$5,B$7:H$7,G$9:M$9),B12,C12)
F12:F39F12=INDEX((B$2:H$2,J$5:P$5,B$7:H$7,G$9:M$9),1,C12,B12)
 
Last edited:
Upvote 0
...but not only are the earlier ones considerably shorter
Shorter and more flexible sure - assuming the OP has 5 rows of data only. Even though I'm not in the business of speculating, but if I were to speculate out of all the scenarios you demonstrated, having a larger data set is most likely.
 
Upvote 0
You could well be right. Hopefully we will get some feedback at some stage. :)
Apologies for the delay in responding. Many responses to look at for which I am thankful.

Maybe I could have been clearer in my post :

1. The entire data range could be huge and will vary.

2. The rows of interest will change and the number of rows could vary.

3. It is the value at the intersection of a row and column in the given rows that I am after.

The solution from hagia_sofia seems to be the most appropriate.

Excel Formula:
=INDEX(CHOOSEROWS(B2:H9,1,3,6,8),2,3)

It allows the a range, the entire range in this case, to be referenced only once, this may need to be a dynamic named range, and is flexible with the row numbers which could take the values from a range.

It creates a dynamic array just containing the rows in which I am interested in which is then interrogated.

The way of referencing a range in my post was interesting.

Excel Formula:
=INDEX($B$2:$H$2:$B$4:$H$4:$B$7:$H$7:$B$9:$H$9,2,3)

It seems that this range is interpreted as $B$2:$H$9 and so

Excel Formula:
=INDEX($B$2:$H$2:$B$4:$H$4:$B$7:$H$7:$B$9:$H$9,2,3)

will return the value from row 2 of the entire data range ($B$3:$H$3), not the desired result.
 
Upvote 0
The way of referencing a range in my post was interesting.

Excel Formula:
=INDEX($B$2:$H$2:$B$4:$H$4:$B$7:$H$7:$B$9:$H$9,2,3)

It seems that this range is interpreted as $B$2:$H$9

Yes, that's correct. The boundaries of a run-on range reference like this will extend from the minimum column/row to the maximum column/row present in the reference and include everything in between.

For example, =D2:F7:A5:B10 will be interpreted as =A2:F10.

The best use case for this concept is with dynamic spill range references, e.g. =A2#:A1 will extend the boundaries of the spill range A2# to include the row above.
 
Upvote 0
Yes, that's correct. The boundaries of a run-on range reference like this will extend from the minimum column/row to the maximum column/row present in the reference and include everything in between.

For example, =D2:F7:A5:B10 will be interpreted as =A2:F10.

The best use case for this concept is with dynamic spill range references, e.g. =A2#:A1 will extend the boundaries of the spill range A2# to include the row above.
That makes sense now, thanks.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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