我有這個類的一些藏品查找值的百分比/計數類VBA
'class properties
public a as collection
public b as collection
public c as collection
A,B的,4c含有例如值「A,A,A,A,B, b,b,b,c,c,c,c,c,c,c「,以及更可能。這些值可以是我們可以假設的任何字母表。得到的百分比爲每個屬性爲每個類,我覺得做這樣的
的(骨架,怎麼我不知道如何準確地做到這一點)
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
任何建議表示讚賞,是新的,到目前爲止我有兩個noobie問題:)既不解決不知道爲什麼:P
可以使用'Scripting.Dictionary'對象這種類型的任務:如果 「鍵」(A,B,C等)不存在然後添加它並將相應的「值」設置爲1.如果已經添加了該鍵,則將該「值」增加1.例如:第一個答案在這裏 - http://stackoverflow.com/questions/9663200/excel-vba -to-count-and-print-distinct-values –
我會試試,謝謝! – trackmeifUcan
@TimWilliams我不確定他想刪除重複項。我想他想要在每個集合中出現一個角色的百分比。 – 2013-08-23 08:10:09