0

I am wondering if there is a way of getting the logarithm of a value for any base.

Specifically I want to get the value of any integer on the base 11.5.

In Excel I have this formula:

=LOG(A1,11.5)

However as this link: Logarithm is different using VBA and Excel function and many others state that the worksheet function is different from the VBA statement.

Is there a way to actually get the base 11.5 logarithm of any integer in VBA?

Community
  • 1
  • 1
ib11
  • 2,530
  • 3
  • 22
  • 55
  • 2
    It's [just math](http://stackoverflow.com/a/9071658/11683). – GSerg May 12 '16 at 07:15
  • 1
    Is there a reason you cannot apply the [WorksheetFunction object](https://msdn.microsoft.com/en-us/library/office/ff834434.aspx) or [Excel Application object](https://msdn.microsoft.com/en-us/library/office/ff194565.aspx) to use the native worksheet function? e.g. `dim x as double: x = worksheetfunction.log(sheet1.cells(1,1), 11.5)` –  May 12 '16 at 07:15
  • Yes, my tagging is off. I am using Word VBA in fact. – ib11 May 12 '16 at 07:16
  • Then create an excel.application object. VBA works across all office applications but you have to create an application object in order to use the native functions. If you can change a word document from excel then you can use excel's native worksheet functions in word. –  May 12 '16 at 07:17
  • +1 for @GSerg I should have pay attention in class... This gave me the answer... https://www.google.com/#q=converting+log+10+to+any+base – ib11 May 12 '16 at 07:18

2 Answers2

4

From my maths textbook:

logb x = logc x / logc b

Therefore in VBA:

Log(x) / Log(11.5)

will give you the base 11.5 logarithm of x, and it doesn't actually matter what the base of VBA's Log function is (although as your link states, it's actually the natural log i.e. base e)

nekomatic
  • 5,988
  • 1
  • 20
  • 27
1

Based on the answer of nekomantic and the comments, this is an extension method to extend the VBA functionality with Log on any base:

Function Logn(base As Double, x As Long)

    Logn = Log(x) / Log(base)

End Function
ib11
  • 2,530
  • 3
  • 22
  • 55