match() to return multiple results

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi I want to apply match() on a column but I want match() function to return not only the position of 1 item but the positions of multiple items since the occurrence is not only one. Is that possible.
For example in this example, want match() to return (1,2, and 3) for me if I tried to match test

=match("test",a1:a6,0)


test
test
hello
test
bye
whatever

<tbody>
</tbody>
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,961
Office Version
  1. 365
Platform
  1. Windows
In that example, it should be 1, 2, and 4. Now you can create an array that contains those values along with FALSE for the non-matching values. But what are you trying to do with the returned result?

This for example, would return the last row with the matching value.

=MAX(IF(A1:A6="test",ROW(A1:A6)))

Confirm with CTRL-SHIFT-ENTER rather than just Enter.
 
Last edited:
Upvote 0

sunny102

Board Regular
Joined
Dec 19, 2016
Messages
102
Hi,

Apply the following array formula
=IFERROR(INDEX(ROW($A$2:$A$60), SMALL(IF($D$2=$A$2:$A$60, ROW($A$2:$A$60)-MIN(ROW($A$2:$A$60))+1, ""), ROW(A1))),"") press CTRL+SHIFT+ENTER

and drag the formula down

it assumes that your list is in column A (from A2 to A60 and matching value is in D2 in this case test should be in D2)
 
Last edited:
Upvote 0

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Thanks for your reply. I have a table which has several columns. the first column has Name, second has phone number, third has Address, the last one has CityName. With Vlookup, I can use the Name as a lookup value to find phone number, address, city name.

I was thinking if I can reverse that by asking user to enter City Name and then excel will return all Names or phone numbers associated with that city.

I just tried your formula and pressed ctr+shift+enter but I got number "4" in the cell I put your formula.

Thanks once again.

In that example, it should be 1, 2, and 4. Now you can create an array that contains those values along with FALSE for the non-matching values. But what are you trying to do with the returned result?

This for example, would return the last row with the matching value.

=MAX(IF(A1:A6="test",ROW(A1:A6)))

Confirm with CTRL-SHIFT-ENTER rather than just Enter.
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
ADVERTISEMENT
If you want to know the native row numbers where "test" occurs...

IF(A1:A6="test",ROW(A1:A6))

If you want to know the positions within a range where "test" occurs...

=IF(A1:A6="test",ROW(A1:A6)-ROW(A1)+1)

Note that these formulas return an array of nil or more values...
 
Upvote 0

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Sorry what I want to get these positions 1,2,4 saved somewhere. So I can go and use index() etc
Thanks

If you want to know the native row numbers where "test" occurs...

IF(A1:A6="test",ROW(A1:A6))

If you want to know the positions within a range where "test" occurs...

=IF(A1:A6="test",ROW(A1:A6)-ROW(A1)+1)

Note that these formulas return an array of nil or more values...
 
Upvote 0

Aladin Akyurek

MrExcel MVP
Joined
Feb 14, 2002
Messages
85,210
Sorry what I want to get these positions 1,2,4 saved somewhere. So I can go and use index() etc
Thanks

Since you want to save them, here is one way:

In C1 enter:

=COUNTIFS(A1:A6,"test")

In C3 control+shift+enter, not just enter, and copy down:

=IF(ROWS($C$3:C3)>$C$1,"",SMALL(IF($A$1:$A$6="test",ROW($A$1:$A$6)-ROW($A$1)+1),ROWS($C$3:C3)))

Note. You can't 'save' such a result in a single cell; rather you can feed such a result to appropriate functions in a formula.
 
Upvote 0

Forum statistics

Threads
1,195,625
Messages
6,010,756
Members
441,568
Latest member
abbyabby

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