A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
You may use either the above formula or the below formula which has been updated so as to cover blank cells in both columns C & D:
Enter below formula as an array formula (CTRL+SHIFT+ENTER) in cell E2 & copy down:
=IF(OR($C2="",$D2=""),"",IF($C2<>$D2,"",SUM(IF(FREQUENCY(IF($C$2:$C$100=$C2,IF($D$2:$D$100<>"",MATCH("~"&$D$2:$D$100,$D$2:$D$100&"",0))),ROW($D$2:$D$100)-ROW($D$2)+1),1))-1))
Regards,
Amit Tandon