运行PERCENTRANK时,我收到"无法获取WorksheetFunction类的PercentRank属性"错误

时间:2016-06-15 18:37:18

标签: excel vba macros percentile

我正在尝试使用PERCENTRANK函数来查找“回答”的百分位数'列在' B'列中。从" Dim x As Double"开始是PercentRank函数启动的地方,我只是包含了剩下的代码来显示我正在做的其他事情。

  Dim response As VbMsgBoxResult
    response = MsgBox("Is This Item Catch Weight?", vbYesNo)
  If response = vbNo Then
    Dim cost, weight, answer As Variant
    Dim myrng As Range
        cost = InputBox("Please Enter PO Cost")
        weight = InputBox("Please Enter Net Weight")
        answer = cost / weight
        MsgBox "Price per KG is: " & answer
        Dim x As Double
            Set ws = ActiveWorkbook.Worksheets("Sheet1")
            Set relevant_array = ws.Range(ws.Range("B1"), ws.Range("B1").End(xlDown))
            x = WorksheetFunction.PercentRank(relevant_array.Address, answer)
            Debug.Print x
        Exit Sub

1 个答案:

答案 0 :(得分:1)

您所看到的是由于PercentRank适用于数组/范围,而不是地址。

尝试将该行更改为:

x = WorksheetFunction.PercentRank(relevant_array, answer)

那应该解决它。