范围没有写入带有VBA UDF的数组......甚至是空的

时间:2017-11-27 19:16:27

标签: vba excel-vba excel

我很难获得插值功能。我希望它采用流体,可变温度和所需属性作为参数返回,并吐出给定温度的插值属性。

我在函数中设置了一些数组,但每当我尝试在工作簿中调用Range时,当我进入调试时,我会为这些数组获得“空”...

UDF有什么东西让我不能正确地写这些东西吗?我错过了一些明显的错误吗?

Function Interpolate(Seed, Independent, Dependent)

Dim Temperatures() As Variant
Dim Properties() As Variant

Select Case Seed

    Case "Air"

        Temperatures = Array(Worksheets("Air Property Table").Range("A4:A38").Value)

        Select Case Dependent

            Case "Viscosity"

                Properties = Worksheets("Air Property Table").Range("E4:E38").Value

            Case "Thermal Conductivity"

                Properties = Sheets("Air Property Table").Range("F4:F38").Value

            Case "Density"

                Properties = Sheets("Air Property Table").Range("I4:I38").Value

            Case "Specific Heat"

                Properties = Sheets("Air Property Table").Range("B4:B38").Value

        End Select


    Case "Water"

        Temperatures = Sheets("Water Property Table").Range("A4:A19").Value

        Select Case Dependent

            Case "Viscosity"

                Properties = Sheets("Water Property Table").Range("E4:E19").Value

            Case "Thermal Conductivity"

                Properties = Sheets("Water Property Table").Range("F4:F19").Value

            Case "Density"

                Properties = Sheets("Water Property Table").Range("I4:I19").Value

            Case "Specific Heat"

                Properties = Sheets("Water Property Table").Range("B4:B19").Value

        End Select


End Select

For i = LBound(Temperatures) To UBound(Temperatures)

    If Temperatures(i) >= Independent Then

    Output = Properties(i - 1) + (Independent - Temperatures(i - 1)) / (Temperatures(i) - Temperatures(i - 1)) * (Properties(i) - Properties(i - 1))

    Exit For

    End If

Next i



ActiveCell.Value = Output




End Function

0 个答案:

没有答案