How to spill multiple results with MATCH?

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
528
Office Version
  1. 365
Platform
  1. Windows
Hello,

I was just playing with MATCH, and I noticed it only returns the position of the first match it finds. I was trying to make it spill out all matching positions, but didn't get anywhere 😅 I thought it would be pretty simple, but I might need more coffee :coffee:😂

Blank power workbook1.xlsx
ABCDEFGHIJ
112341actual result:1
2intended result:15
3
4abcdaactual result:1
5intended result:15
6
Sheet7
Cell Formulas
RangeFormula
H1H1=MATCH(1,A1:E1,0)
H4H4=MATCH("a",A4:E4,0)


Thanks for any input! 🤗
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
The Match function will only ever find the 1st match, that is what it's designed to do. You would need to use the Filter function to get all the matches.
 
Upvote 0
Hi

=XLOOKUP(1,A1:E1,COLUMN(A1:E1))
=XLOOKUP(1,A1:E1,COLUMN(A1:E1),,,-1)
 
Upvote 0
Thanks all!

@Fluff How about this:

Blank power workbook1.xlsx
ABCDEFGHIJKL
1123411result:156
2
3abadearesult:136
4
Sheet7
Cell Formulas
RangeFormula
I1:K1I1=LET(a,A1:F1,f,IF(a=1,1,0)*SEQUENCE(,COUNT(IFERROR((a)/1,1)),1,1),FILTER(f,f>0))
I3:K3I3=LET(a,A3:F3,f,IF(a="a",1,0)*SEQUENCE(,COUNT(IFERROR((a)/1,1)),1,1),FILTER(f,f>0))
Dynamic array formulas.
 
Upvote 0
I would use
Excel Formula:
=FILTER(COLUMN(A1:F1),A1:F1=1)
 
Upvote 0
That seems to work only if the cells start at column A, so I adjusted your formula like this:

Blank power workbook1.xlsx
ABCDEFGHIJKLMNO
1123411result:156
2378
3156
4
5abadearesult:136
6358
7136
8
91
103
118
121
132
141
155
16
17result:11
1844
1966
20
21
Sheet7
Cell Formulas
RangeFormula
K1:M1K1=LET(a,C1:H1,f,IF(a=1,1,0)*SEQUENCE(,COUNT(IFERROR((a)/1,1)),1,1),FILTER(f,f>0))
K2:M2K2=FILTER(COLUMN(C1:H1),C1:H1=1)
K3:M3K3=LET(r,C1:H1,cr,COLUMN(r),rr,ROW(r),s,IF(COUNT(cr)>COUNT(rr),COLUMN(r),ROW(r)),FILTER(s-MIN(s)+1,r=1))
K5:M5K5=LET(a,C5:H5,f,IF(a="a",1,0)*SEQUENCE(,COUNT(IFERROR((a)/1,1)),1,1),FILTER(f,f>0))
K6:M6K6=FILTER(COLUMN(C5:H5),C5:H5="a")
K7:M7K7=LET(r,C5:H5,cr,COLUMN(r),rr,ROW(r),s,IF(COUNT(cr)>COUNT(rr),COLUMN(r),ROW(r)),FILTER(s-MIN(s)+1,r="a"))
C17:C19C17=FILTER(ROW(B9:B15)-MIN(ROW(B9:B15)-1),B9:B15=1)
D17:D19D17=LET(r,B9:B15,cr,COLUMN(r),rr,ROW(r),s,IF(COUNT(cr)>COUNT(rr),COLUMN(r),ROW(r)),FILTER(s-MIN(s)+1,r=1))
Dynamic array formulas.



Now it can recognize if the range is horizontal or vertical :cool:
 
Upvote 0
In that case I would use
Excel Formula:
=LET(a,C1:H1,FILTER(SEQUENCE(,COLUMNS(a)),a=1))
 
Upvote 0
I see. With your latest formula, I was trying to make it automatically recognize whether the range is horizontal or vertical. Is this the best way, or there is a better way:

Blank power workbook1.xlsx
ABCDEFGHIJKLMNO
1123411result:156
2
3abadearesult:136
4
5a
63
78
81
9a
101
115
12
13result:41
1465
15
16
17
Sheet8
Cell Formulas
RangeFormula
K1:M1K1=LET(a,C1:H1,IFERROR(FILTER(SEQUENCE(,COLUMNS(a)),a=1),FILTER(SEQUENCE(ROWS(a),),a=1)))
K3:M3K3=LET(a,C3:H3,IFERROR(FILTER(SEQUENCE(,COLUMNS(a)),a="a"),FILTER(SEQUENCE(ROWS(a),),a="a")))
C13:C14C13=LET(a,B5:B11,IFERROR(FILTER(SEQUENCE(,COLUMNS(a)),a=1),FILTER(SEQUENCE(ROWS(a),),a=1)))
D13:D14D13=LET(a,B5:B11,IFERROR(FILTER(SEQUENCE(,COLUMNS(a)),a="a"),FILTER(SEQUENCE(ROWS(a),),a="a")))
Dynamic array formulas.
 
Upvote 0
Personally, I would just use two different formulae, rather than making things far more complex than they need to be.
 
Upvote 0
I wanted to make a convenient LAMBDA that would automatically work whether the selected range is horizontal or vertical :cool:

I turned your formula into this, which works very well:

Excel Formula:
=LET(a,C1:H1,hv,IF(COLUMNS(a)>ROWS(a),"h","v"),FILTER(SWITCH(hv,"h",SEQUENCE(,COLUMNS(a)),SEQUENCE(ROWSS(a),)),a=1))

Thank you! 🤗
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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