MATCH comma separated list of numbers to a column in Excel (no macros, no TEXTJOIN)

老子叫甜甜 提交于 2021-01-29 05:06:55

问题


I'm trying to match a cell with comma separated numbers (M) against a column of numbers (B), such that if any of the comma separated numbers do NOT appear in the column, the result is false.

I have already this solution:

{=COUNT(MATCH(TRIM(MID(SUBSTITUTE(M2,",",REPT(" ",100)),(Num_Array-1)*100+1,100)),$B$2:$B$7,0))=(LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1)}

at this link:

https://www.mrexcel.com/forum/excel-questions/654920-match-comma-delimited-values-cell-against-individual-values-column.html

which works perfectly if all the values are text. But if all the values are numbers, it always returns false.

Test data I used is: test data


回答1:


You will need to iterate the values in each cell and test:

=SUMPRODUCT(--(ISNUMBER(MATCH(--TRIM(MID(SUBSTITUTE(M2,",",REPT(" ",999)),(ROW($XFD$1:INDEX($XFD:$XFD,LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1))-1)*999+1,999)),$B:$B,0))))=LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1


Using your COUNT array formula:

=COUNT(MATCH(--TRIM(MID(SUBSTITUTE(M2,",",REPT(" ",999)),(ROW($XFD$1:INDEX($XFD:$XFD,LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1))-1)*999+1,999)),$B:$B,0))=LEN(M2)-LEN(SUBSTITUTE(M2,",",""))+1

Needs confirmation with Ctrl-Shift-Enter to work.

I prefer the SUMPRODUCT because it does not need the Ctrl-Shift-Enter confirmation.



来源:https://stackoverflow.com/questions/56430464/match-comma-separated-list-of-numbers-to-a-column-in-excel-no-macros-no-textjo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!