我们能否让这个vba excel功能更快地执行

时间:2017-10-15 01:16:53

标签: excel vba excel-vba function

我写了这段代码来估算插值降水数据。我在stackoverflow论坛上得到了一些人的帮助。请问,当我运行这段代码时,它运行得很好,但问题是,我的计算机有点慢,所以我必须等待5分钟才能插入数据。

拜托,有没有办法让这个功能更快?

感谢您的帮助!

Function IDWW(Value1, Value2, Value3, Dist1,Dist2,Dist3)
    Dim a1 As Variant
    Dim b1 As Variant
    Dim a2 As Variant
    Dim b2 As Variant
    Dim a3 As Variant
    Dim b3 As Variant

    If Value1 <> "" And Dist1 <> "" Then
        a1 = Value1 / (Dist1) ^ 2
        b1 = 1 / (Dist1) ^ 2
    Else
        a1 = 0
        b1 = 0
    End If

    If Value2 <> "" And Dist2 <> "" Then
        a2 = Value2 / (Dist2) ^ 2
        b2 = 1 / (Dist2) ^ 2
    Else
        a2 = 0
        b2 = 0
    End If

    If Value3 <> "" And Dist3 <> "" Then
        a3 = Value3 / (Dist3) ^ 2
        b3 = 1 / (Dist3) ^ 2
    Else
        a3 = 0
        b3 = 0
    End If

    'Avoid a problem if all 3 distances are empty
    If b1 + b2 + b3 = 0 Then
        IDWW = 0
    Else
        IDWW = (a1+a2+a3) / (b1+b2+b3)
    End If
End Function

0 个答案:

没有答案