与直接 excel 中的实际公式相比,UDF 给出不同的结果

UDF gives different result compared to actual formula in excel direct

我在excel中有一个公式如下:

=Round(33.468*(Log(Log(M+0.8)))+23.097;2)

因为我有大量数据并且需要经常使用它,所以我根据以下公式创建了一个 UDF:

Function visco(M)

visco = Round(33.468 * (Log(Log(M + 0.8))) + 23.097, 2)

End Function

然而,当我为 M 插入一个值时,每个值都不同,直接在单元格中的 excel 公式是正确的,而 UDF 结果是错误的。

如果有人能解释一下,我不确定这里发生了什么

谢谢

vba 中的

Log 不等于工作表中的 LOG。在 vba 中是 Log(e) 而不是 Log(10)。

要么使用工作表函数:

visco = Round(33.468 * (Application.Log(Application.Log(M + 0.8))) + 23.097, 2)

或除以所需碱基的对数。

visco = Round(33.468 * ((Log((Log(M + 0.8) / Log(10#))) / Log(10#))) + 23.097, 2)