[TABLE="width: 240"]
<colgroup><col style="WIDTH: 48pt" span="5" width="64"></colgroup><tbody>[TR]
[TD="class: xl63, width: 64, bgcolor: transparent"]
Col D[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"]
Col O[/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"][/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"][/TD]
[TD="class: xl63, width: 64, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl64, bgcolor: transparent"]
A
[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20111[/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20111[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
2[/TD]
[/TR]
[TR]
[TD="class: xl64, bgcolor: transparent"]
B[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20111[/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20112[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
1[/TD]
[/TR]
[TR]
[TD="class: xl64, bgcolor: transparent"]
A[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20111[/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl64, bgcolor: transparent"]
B[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20111[/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl64, bgcolor: transparent"]
C[/TD]
[TD="class: xl63, bgcolor: transparent, align: right"]
20112[/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[TD="class: xl63, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]
R2, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($D$2:$D$6<>"",IF($O$2:$O$6=Q2,
MATCH("~"&$D$2:$D$6,$D$2:$D$6&"",))),
ROW($D$2:$D$6)-ROW($D$2)+1),1))
If no special meaning chars surround the entries in column D, the "~"& and &"" bits can be safely removed from the foregoing formula if so desired.