有没有办法拨打Application.Worksheetfunction.Percentile(resultColl)
,其中resultColl
是Collection
?
我尝试了它并返回Unable to get Percentile property of the WorksheetFunction class
错误。
修改
我尝试先将该集合转换为数组:
Function convertToArray(resultColl As Collection)
Dim resultArray() As Variant
ReDim resultArray(1 To resultColl.Count)
Dim i As Long
For i = 1 To resultColl.Count
resultArray(i) = resultColl.Item(i)
Next
convertToArray = resultArray
End Function
并在Percentile
函数中使用该数组:
Application.WorksheetFunction.Percentile( _
convertToArray(clientsColl.Item(1).getSumLosses), 0.99)
但现在它在wrong number of arguments or invalid property assignment
函数返回convertToArray
错误,即使在我创建的这个测试示例中,该函数也能正常工作:
Sub testConvert() 'this works fine
Dim testColl As Collection
Set testColl = New Collection
testColl.Add "apple"
testColl.Add "orange"
testColl.Add "pineapple"
Dim tempArray() As Variant
tempArray = convertToArray(testColl)
MsgBox (tempArray(1))
End Sub
clientsColl.Item(1).getSumLosses
是Collection
:
在Client
课程内:
Private sumLosses As Collection 'the collection of numbers, a percentile of which I need to calculate
Private Sub Class_Initialize()
Set sumLosses = New Collection
End Sub
Public Property Get getSumLosses()
Set getSumLosses = sumLosses
End Property
EDIT2:
将Percentile
函数调用更改为:
Dim tempArray() As Variant
tempArray = convertToArray(clientsColl.Item(1).getSumLosses)
resultDict.Add "UL: " & _
Application.WorksheetFunction.Percentile(tempArray, 0.99)
错误发生在resultDict
的行上。
答案 0 :(得分:-1)
想出来。添加到字典是以错误的方式完成的:
resultDict.Add "UL: " & _
Application.WorksheetFunction.Percentile(tempArray, 0.99)
而不是
resultDict.Add "UL: ", _
Application.WorksheetFunction.Percentile(tempArray, 0.99)