从excel图表与vba获得具体的价值

我正试图从Excel图表中获得具体的价值。 这是创build我的图表的代码(我创build了一个颠倒的二项分布图):

Dim lim As String Dim N As Long N = Range("C4").Value Dim x, s, p As Double x = Range("C6") 'event number s = Range("C5") 'sample size Dim g() As Long Dim h() As Double Dim k() As Double Dim prob() As Double ReDim g(N) ReDim prob(N) ReDim h(N) ReDim k(N) For i = 1 To N g(i) = i h(i) = i / N k(i) = 1 - h(i) prob(i) = WorksheetFunction.BinomDist(x, s, h(i), False) * 100 End If 

这里是图表: 在这里输入图像说明

我需要第二次在分布曲线上y是0的点。

在你的For循环结束时,你可以检查if prob(i) = 0 And Prob(i-1) > 0 ,并保存这个点的索引。 这“太”简单,但如果这只是这种分配,它会做到这一点:

 Dim targetIndex As Integer For i = 1 To N g(i) = i h(i) = i / N k(i) = 1 - h(i) prob(i) = WorksheetFunction.BinomDist(x, s, h(i), False) * 100 If i > 1 Then 'check if this is not the first point If prob(i) = 0 And prob(i-1) <> 0 Then targetIndex = i End If Next '// Now your point is the couple (targetIndex, prob(targetIndex))