Excel 如何在公式中引用集合

Excel 如何在公式中引用集合,excel,vba,Excel,Vba,我只想引用公式中的集合。像 假设我已经知道如何创建集合和数组,并且已经在宏中这样做了,集合实际上是一个只有一列的集合,Textstring是一个数组向量 'For every value of i in Textstring, I want to count the occurrence of that value in all the values of 'Collection' For i = 1 to Whatever =COUNTIF(Collection, """ &

我只想引用公式中的集合。像

假设我已经知道如何创建集合和数组,并且已经在宏中这样做了,集合实际上是一个只有一列的集合,Textstring是一个数组向量

'For every value of i in Textstring, I want to count the occurrence of that value in all the values of 'Collection'
For i = 1 to Whatever 
    =COUNTIF(Collection, """ & TextString(i) & """)
Next i
我想知道的是如何使上述代码工作

在以下情况下,它应该像正常计数器一样工作:

'ie: "=COUNTIF('Sheet1'!A1:A10, ""blah"")"

不能使用
COUNTIF
,如果查看函数的参数,它需要一个范围对象

我唯一的建议是做如下操作,即将其写在工作表中,然后将该范围用作函数的参数

Public Sub CollectionToRange()
    Dim objCollection As New Collection, i As Long

    For i = 1 To 10
        objCollection.Add i
    Next

    ' Convert the collection to a range.
    For i = 1 To objCollection.Count
        Sheet1.Cells(i, 1) = objCollection.Item(i)
    Next

    ' Pass the range into the worksheet function.
    Debug.Print "CountIf Result = " & WorksheetFunction.CountIf(Sheet1.Range("A1:A" & objCollection.Count), ">3")

    ' Perform a clean up if required.
End Sub


不确定这是否有用。

如果是这样,你会怎么做?特别是对于多个if语句。嗯。。。取决于你要做多少,可能有点痛苦。您希望为集合中的多少个属性执行此操作?我们谈了多少?您可以使用FOR循环以旧式的方式进行操作。不管怎样,当你把它写在纸上的时候,你就有了它。我倾向于认为使用内置函数更好,更可能无缝工作。好吧。如何引用集合中的所有项,例如:application.count(collection)如果您问我认为您在问什么,那么获取集合的计数就像我的示例中的objCollection.count。。。这就是你的意思吗?更像是:对于i=1的空话,对于j=1的空话,对于k=1的空话,“=COUNTIFS(Coll1,Array1(k,i),Coll2,Array2(j))下一个k,下一个j,下一个i