答案1
我们建立一个列列表A唯一标识符并将其放入列中埃然后执行一组循环来计算其他列中的唯一值:
Sub Macro1()
Dim N As Long, i As Long
Dim c As Collection, v As Variant
Dim M As Long, j As Long, rc As Long
Dim K As Long
Columns("A:A").Copy Columns("E:E")
Range("E:E").RemoveDuplicates Columns:=1, Header:=xlNo
rc = Rows.Count
M = Cells(rc, "A").End(xlUp).Row
N = Cells(rc, "E").End(xlUp).Row
For i = 1 To N
v = Cells(i, "E").Text
For K = 2 To 4
Set c = Nothing
Set c = New Collection
For j = 1 To M
If v = Cells(j, "A").Text Then
On Error Resume Next
c.Add Cells(j, K).Text, CStr(Cells(j, K).Text)
On Error GoTo 0
End If
Next j
Cells(i, K + 4).Value = c.Count
Next K
Next i
End Sub