Probably not the best solution but get the job done. Please note it is case-sensitive and please make sure to press Ctrl+Shift+Enter upon finishing this formula.
{=SUM(--(EXACT("!"&TRIM(MID(SUBSTITUTE($A2,",",REPT(" ",100)),(ROW(INDIRECT("1:"&LEN($A2)))-1)*100+1,100)),"!"&B1)))}
You can replace !
in the above formula with a unique symbol that will never appear in the text string to be safer.
The logic is to SUBSTITUTE the comma ,
with and long string of blanks, then use MID to find each value in the text string and return the result as an array, then use EXACT to match each value in the array with the look up value and return a new array of TRUE
and FALSE
, then SUM up all TRUE
which will give the count of the look up value.
![Solution3](https://i.stack.imgur.com/Tws8Z.png)
UPDATE #2
As requested by OP, here is one way of solving the second query which is to match the same value with the same occurrence from two text strings separated by comma ,
.
![Update2](https://i.stack.imgur.com/dW9RD.png)
The formula in Cell C2
is from the original solution which is used to find the occurrence of a given value in a text string;
The formula for Range C6:K6
is an array formula as shown below. I used a helper row to layout the matching values, and excluding the one that has 0
count for both data set;
{=IFERROR(INDEX($C$1:$K$1,,AGGREGATE(15,7,COLUMN(INDIRECT("1:"&COLUMNS($C$1:$K$1)))/($C$2:$K$2=$C$3:$K$3)/($C$2:$K$2>0),COLUMN()-2))&",","")}
The formula in Cell L8
is concatenating all values from Range C6:K6
and remove the last comma ,
from the final text string:
=LEFT(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6),LEN(CONCATENATE(C6,D6,E6,F6,G6,H6,I6,J6,K6))-1)