【发布时间】:2018-02-20 15:20:01
【问题描述】:
我是 VBA 编程的新手,并且编写了一个用于插值的 VBA 函数。 我尝试从单元格 C17 和 C 列中的其他单元格获取输入到函数“WindPressure”
该函数然后从列 C( 离地高度 z (m) ) 获取输入并进行插值以获得设计风压,但由于圆形误差而失败。
代码如下:
Function WindPressure(z As Double) As Double
Dim Row_Nos As Integer
Dim x1 As Double
Dim x2 As Double
Dim x3 As Double
Dim y1 As Double
Dim y2 As Double
Dim y3 As Double
' Select first line of data.
Range("T13").Select
' Set Nos of row to interploate
Row_Nos = 12
' Interpolation for Design Wind pressure
For i = 0 To Row_Nos
' Case 1: <= 5m
If i = 0 And z <= ActiveCell.Value Then
WindPressure = ActiveCell.Offset(0, 1).Value
' Shifting Back
ActiveCell.Offset(0, -1).Select
'Exit If Enter this if statement
Exit Function
ElseIf i >= 0 And z <= ActiveCell.Value Then
' Case 2: > 5m
x1 = z
x2 = ActiveCell.Offset(-1, 0).Value
x3 = ActiveCell.Offset(2, 0).Value
y2 = ActiveCell.Offset(-2, 1).Value
y3 = ActiveCell.Offset(2, 0).Value
y1 = ((x1 - x3) / (x2 - x3) * (y2 - y3)) + y3
WindPressure = y1
' Shifting Back
ActiveCell.Offset(-1, -1).Select
'Exit If Enter this if statement
Exit Function
End If
ActiveCell.Offset(1, 0).Select
Next i
End Function
- 谁能告诉我脚本中的哪一步是错误的
- 有没有方便的功能测试?因为它不像是直接按F5键执行的程序
非常感谢您的关注和帮助。
【问题讨论】: