當我嘗試運行此宏,我收到了味精說值分配給一個子產生編譯錯誤:參數不可選
Compile Error: Argument Not optional
,它凸顯了pressureDrop最後的公式所示。
Public Sub pressureDrop(p As Double, L As Double, _
D As Double, u As Double, _
e As Double, w As Double)
Dim A As Double, B As Double, f As Double, k As Double
Dim Re As Double, Rng1 As Range, Rng2 As Range
Re = p * D * u/w
With WorksheetFunction
A = (2.457) * .Ln(1/(7/Re)^0.9 + (0.27 * e/D))
B = (37530/Re)^16
f = 2 * ((8/Re)^12 + 1/(A + B)^(3/2))^(1/12)
Set Rng1 = Range("D2:D29")
Set Rng2 = Range("E2:E29")
k = .SumProduct(Rng1, Rng2)
End With
pressureDrop = p * ((4 * f * (L/D) + k) * (u^2)/2)
End Sub
您正在嘗試編寫'Function',而不是'Sub'。將聲明更改爲'Public Function pressureDrop(...' –
主要問題是您的代碼試圖給Sub()分配一個返回值。返回值的唯一方法是從Function()。但是如果你提供更多的環境,社區將能夠更好地指導您 –