2017-07-26 61 views
1

我想從Excel圖表中獲取特定值。這是我創建的圖表(我創建了一個反向二項式分佈圖)代碼:從excel圖表中獲取特定值與vba

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的分佈曲線第二個時間點。

+0

嗨,這是你的所有代碼?或者For循環中有更多? – Moosli

+0

這是我所有的代碼。 – OykuA

回答

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))