运行时错误“1004”:无法获取WorksheetFunction类的Combin属性

Excel 2013中的工作簿中具有VBAfunction,可根据泊松分布计算p值。 当下面的代码中的事件variables超过1029时,我得到运行时错误“1004”:无法获取WorksheetFunction类的Combin属性 。 只要事件1和事件2的总和保持在1029或更低,就没有问题,并且macros执行正确。

有没有人知道一种方法来获得这个更高的数字正常工作? 任何指导,非常感谢!

Sub poisson_meansB() Dim events1 As Long Dim events2 As Long Dim days1 As Long Dim days2 As Long events1 = Sheet1.Range("B6").Value events2 = Sheet1.Range("C6").Value days1 = Sheet1.Range("B7").Value days2 = Sheet1.Range("C7").Value If events2 > 0 Then events = events1 + events2 p_c = days1 / (days1 + days2) p_lo = 0 p_hi = 0 For i = 0 To events1 poisson_p_value_term = Application.WorksheetFunction.Combin(events, i) * Application.WorksheetFunction.Power(p_c, i) * Application.WorksheetFunction.Power(1 - p_c, events - i) p_lo = p_lo + poisson_p_value_term Next i For i = events1 To events poisson_p_value_term = Application.WorksheetFunction.Combin(events, i) * Application.WorksheetFunction.Power(p_c, i) * Application.WorksheetFunction.Power(1 - p_c, events - i) p_hi = p_hi + poisson_p_value_term Next i p = Application.WorksheetFunction.Min(2 * p_lo, 2 * p_hi) Sheet1.Range("C13") = p Else Sheet1.Range("C13") = "-" End If End Sub 

在Excel 2013中,可以通过公式返回的最大正数为1.7976931348623158e + 308您的数字很可能会达到比您所描述的情况更高的值。 您可以通过尝试使用variables的因子在工作表上执行COMBIN函数并查看它是否返回#NUM错误来确认这一点。

一种可能的解决scheme是安装XNumbers加载项并使用其xComb_big函数。 XNumbers是一个免费的工具,允许使用大数量和提高精度。 据说在97-2010版本的Excel版本上工作。 我不知道它是否会在2013年工作。但是如果这样做的话,它可以configuration为指数高达2147000000和有效数字高达32760(你可能不想那么多,但它是可configuration的,默认安装的位数较less)。

我打赌这个问题将消失,如果你显式声明所有的variables: eventsp_cp_lop_hiipoisson_p_value_term