简体   繁体   中英

I Keep getting a #value error in Excel VBA

So I wrote a quick function in VBA for Excel, but every time I call it, it gives me a #value error. I don't know what I am doing wrong. Can anyone help?

Function h(UA, k, A, Af_At, Delta, l)
h1 = 0
m = (2 * h1 / k / Delta) ^ 0.5
ml = m * l
Nf = WorksheetFunction.Tanh(ml)
No = 1 - Af_At * (1 - Nf / ml)
UA1 = h1 * A * No / 2

While UA > UA1
    UA_old = UA1
    h_old = h1
    h1 = h1 + 0.5
    m = (2 * h1 / k / Delta) ^ 0.5
    ml = m * l
    Nf = WorksheetFunction.Tanh(ml)
    No = 1 - Af_At * (1 - Nf / ml)
    UA1 = h1 * A * No / 2
Wend

h = h_old + (UA - UA_old) * (h1 - h_old) / (UA1 - UA_old)

End Function

I call it using: =h(10,1,1,1,1,1) in the insert function bar.

Division by zero at

No = 1 - Af_At * (1 - Nf / ml)

m1 is zero because h1 is zero.

You should change:

h1 = 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM