Logarithm is different using VBA and Excel function

后端 未结 2 756
轻奢々
轻奢々 2020-12-06 20:05

I\'m trying to get the log of a number but it looks like the Worksheet function gives one answer, and VBA another.

In VB, using Log(Range(\"A2\")) where

2条回答
  •  盖世英雄少女心
    2020-12-06 20:31

    Function roundit1(nn As Variant, sd As Variant)
        nn = Val(nn)
        If Not (nn = 0) Then
            xx = (1 + Int(Log(Abs(nn)) / Log(10)))
        Else
            xx = 0
        End If
        ' significant digits
        roundit = sd - xx
        If roundit < 0 Then roundit = 0
       roundit1 = Round(nn, roundit)
    End Function
    

提交回复
热议问题