Search code examples
arraysexcelduplicatesconcatenationranking

Ranks of first and last occurrence of a duplicate inside an array placed in concatenated cell - Excel


I am trying to find a formula to identify the rank of the first occurrence of a duplicate inside an array and the rank of its last occurrence and place these numbers inside a concatenated cell. This formula would be placed to the right (following column) of every single occurrence of a duplicate.

I would also like to place a hyphen between those values just like in the formula below:

= (rank # first occurrence) & “ - “ & (rank # last occurrence)

Please have a look at the image in case my description is unclear (image reflects what I would like to achieve in column D)

enter image description here


Solution

  • Based on data in A3:D12. In D3:

    =IF(COUNTIF($C$3:$C$12,C3)>1,MATCH(C3,$C$3:$C$12,0)&"-"&LOOKUP(2,1/($C$3:$C$12=C3),ROW($C$3:$C$12)-MIN(ROW($C$3:$C$12))+1),"")

    Regards