简体   繁体   中英

How do I use INDEX MATCH to return multiple values?

I have a 2D matrix of binary values. I'd like to find all the 1's in a row, and return their respective header in the form of an array or comma delimited string in one cell.

I could do it in VBA, but for my knowledge I wanted to know if there was a handy way to do it in Excel.

Assuming your matrix is located at B6:F12 (adjust ranges in formula and arguments as required)

Enter this FormulaArray at G7 and copy till last record (Enter the FormulaArray pressing [Ctrl] + [Shift] + [Enter] simultaneously, you shall see { } around the formula if entered correctly)

=TRIM(CONCATENATE(
IF($B7:$B12,$B$6,""),CHAR(32),
IF($C7:$C12,$C$6,""),CHAR(32),
IF($D7:$D12,$D$6,""),CHAR(32),
IF($E7:$E12,$E$6,""),CHAR(32),
IF($F7:$F12,$F$6,"")))

This formula concatenates the result of 5 fields separated by a blank space. You'll have to add one more argument per additional field.

在此处输入图片说明

This standard formula will also do the trick:

=TRIM(SUBSTITUTE(CONCATENATE(
IF($B7,", "&$B$6,""),
IF($C7,", "&$C$6,""),
IF($D7,", "&$D$6,""),
IF($E7,", "&$E$6,""),
IF($F7,", "&$F$6,"")),",","",1))

Both formulas will certainly become longer as the number of fields increases, however as the formula is quite repetitive an excel formula can be used to build it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM