使用vba从excel图表中获取特定值

时间:2017-07-26 07:18:19

标签: excel vba

我想从excel图表中获取特定值。这是创建我的图表的代码(我创建了一个反向二项分布图):

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

这是图表:enter image description here

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

1 个答案:

答案 0 :(得分: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))