I try to find a formula to compare two range of cells, say A1:E1 (1,2,3,4,5) and A2:E2 (2,3,1,4,5) , and if they have the same values (the numbers can be in different order), it will show the numbers of matches. The cells may have repetitions ( e.g, 1,2,2,2,3). Thanks.

Shortly, if we consider two range cells as two groups, I need a formula to show the number of matches. Numbers may not be in an order, there can be repetitions.

Edit:

I found this formula but it doesn't do the job in this task. =SUMPRODUCT(COUNTIF(A1:E1,A2:E2))

Example1: {1,1,1,1,1} and {1,1,1,1,1} here the number of matches should be 5. Example2: {1,2,4,5,6} and {1,2,2,4,5} here the number of matches should 4. And above formula doesn't give the correct results.