查找类vba中的值/百分比值

我有这个类与一些集合

'class properties public a as collection public b as collection public c as collection 

a,b,c包含例如“a,a,a,a,b,b,b,b,c,c,c,c,c,c,c”的值,并且b
和c,更可能。 这些值可以是我们可以假定的任何字母表。 为每个class级获得每个财产的百分比,我想这样做
(骨架,因为我不知道该怎么做)

  for each class in collectionOfclassobjects for each ca in class.a 'here am supposed to count all a's and b's divide by class.a.count but am not sure how to do this, I have an idea of adding the first item, and everytime it occurs i add it or add a count, when it's a create collection when its a, add it, when its b create new collection, and so on i have a collection of each value and i can easily print the count/total count and the name next ca for each cb in class.b next cb for each cc in class.c next cc next class 

任何build议表示赞赏,是新的,到目前为止,我有两个noobie问题:)既不解决不知道为什么:P

运行以下过程,并等待消息框最后popup。 它会告诉你的细节

结果

 Sub Percentage() Dim a As Collection Set a = New Collection a.Add "a" a.Add "a" a.Add "a" a.Add "a" a.Add "b" a.Add "b" a.Add "b" a.Add "b" a.Add "c" a.Add "c" a.Add "c" a.Add "c" a.Add "c" a.Add "c" a.Add "c" Dim i As Long, cnt As Long cnt = 0 ' checking the percentage of occurance of letter 'a' For i = 1 To a.Count If a.Item(i) = "a" Then cnt = cnt + 1 Next i MsgBox "'a' occurs " & cnt & " times in collection A" & _ vbCrLf & vbCrLf & " which is " & Format((cnt / a.Count), "0.0%") & " of the entire collection" End Sub