我喜歡輕鬆Gary's Student
方法。
此處參考的是使用用戶定義函數的VBA解決方案。例如:
A B
1 52c2ff91763f4a572d8b45e6 `=COUNTIDS(A1)` = 4
2 52c2ff91763f4a572d8b45e6, 52c2ff91763f4a572d8b45e6
3 52c2ff91763f4a572d8b45e6
4 52b46bfc763f4ad9198b45ab, 533c0cba763f4a505e8b46db
一個VBA模塊內部此代碼:
Function CountIDs(id As Range)
Dim ids As Range, cl As Range, cnt As Long, arr As Variant, i As Integer
Set ids = Range("A1:A" & Range("A1").End(xlDown).Row) //amend to suit your set-up
cnt = 0
For Each cl In ids
If InStr(1, cl, ",", vbTextCompare) Then
arr = Split(cl, ",")
For i = 0 To UBound(arr)
If VBA.Trim(arr(i)) = id Then
cnt = cnt + 1
End If
Next i
Else
If cl = id Then
cnt = cnt + 1
End If
End If
Next
CountIDs = cnt
End Function
做多的ID對實際等試算表方括號括起? –