如果我们有好几列有内容,而我们希望在新列中将有内容的列的标题显示出来,那么我们怎么做呢?
Excel - TEXTJOIN function
1. Stackoverflow - How to concatenate column titles if cells in a range contains a specific text/character
2. Stackoverflow - Finding a specific value and returning column headers in Excel
EXAMPLE:
Indexing | Year 1 | Year 2 | Year 3 | Year 4 | Year 5 | Year 6 | Year 7 | Year 8 |
---|---|---|---|---|---|---|---|---|
? | - | 1 | - | - | - | - | - | - |
? | - | - | 2 | - | - | - | - | - |
? | - | - | - | 3 | - | - | - | 15 |
? | - | - | - | - | 4 | - | - | - |
在开始,我们曾经使用INDEX MATCH的方式,但是没有成功,一直是N/A https://superuser.com/questions/1300246/if-cell-contains-value-then-column-header 所以我们后来改为TEXTJOIN函数,他可以显示值,也可以显示值的标题,还可以多个列有值的时候同时显示。
期望效果:
Indexing | Year 1 | Year 2 | Year 3 | Year 4 | Year 5 | Year 6 | Year 7 | Year 8 |
---|---|---|---|---|---|---|---|---|
Year 2 | - | 6 | - | - | - | - | - | - |
Year 3 | - | - | 2 | - | - | - | - | - |
Year 4,Year 8 | - | - | - | 4 | - | - | - | 15 |
Year 5 | - | - | - | - | 5 | - | - | - |
=TEXTJOIN(", ",TRUE,IF(ISNUMBER(B2:I2),$B$1:$I$1,""))
如果是想要显示值,则:
代码语言:javascript复制=TEXTJOIN(", ",TRUE,IF(ISNUMBER(B2:I2),B2:I2,""))
其中,ISNUMBER(B2:I2)是判断值是不是数字,可以根据情况改成是不是空白ISBLANK()。
This is an array formula, so you need to enter it using Ctrl Shift Enter after entering formula instead of just Enter. It will add {} to your formula.