SOLVED

In VBA how a create a 'log' calculation?

%3CLINGO-SUB%20id%3D%22lingo-sub-2365510%22%20slang%3D%22en-US%22%3EIn%20VBA%20how%20a%20create%20a%20'log'%20calculation%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2365510%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20so%20I%20want%20to%20create%20a%20function%20in%20excel%20VBA%20that%20is%20it%3A%20'%3D%201.16650%20-%200.07063%20log%20(CX%20%2B%20SI%2B%20SB)'%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20don't%20know%20how%20to%20make%20'log'%20work%2C%20because%20I%20can't%20simply%20digit%20'log'%2C%20it%20will%20not%20allow%2C%20it%20will%20say%20'it%20was%20expected%3A%20end%20of%20instruction'%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%20about%20my%20English%2C%20not%20my%20first%20language.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2365510%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2365560%22%20slang%3D%22en-US%22%3ERe%3A%20In%20VBA%20how%20a%20create%20a%20'log'%20calculation%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2365560%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1057059%22%20target%3D%22_blank%22%3E%40rawlc%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20VBA%2C%20you%20have%20to%20specify%20multiplication%20explicitly%20by%20using%20*%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E...%20%3D%201.1665%20-%200.07063%20*%20Log(CX%20%2B%20SI%20%2B%20SB)%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2365829%22%20slang%3D%22en-US%22%3ERe%3A%20In%20VBA%20how%20a%20create%20a%20'log'%20calculation%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2365829%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20thanks%20for%20the%20advising.%20In%20fact%20it%20work%20but%20the%20final%20result%20get%20wrong%20no%20matter%20what%20I%20do%2C%20I%20tried%20to%20specify%20by%20parentheses%20the%20order%20of%20the%20calcule%20but%20still%20didn't%20work%20properly.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2365847%22%20slang%3D%22en-US%22%3ERe%3A%20In%20VBA%20how%20a%20create%20a%20'log'%20calculation%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2365847%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1057059%22%20target%3D%22_blank%22%3E%40rawlc%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EKeep%20in%20mind%20that%20the%20Log%20function%20in%20VBA%20is%20the%20natural%20logarithm%20(base%20e%20%3D%202.7172...).%20It%20corresponds%20to%20the%20worksheet%20function%20LN%2C%20not%20to%20he%20worksheet%20function%20LOG%20(base%2010).%3C%2FP%3E%0A%3CP%3EIf%20you%20need%20to%20use%20the%2010-based%20logarithm%2C%20use%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E...%20%3D%201.1665%20-%200.07063%20*%20Log(CX%20%2B%20SI%20%2B%20SB)%20%2F%20Log(10)%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi, so I want to create a function in excel VBA that is it: '= 1.16650 - 0.07063 log (CX + SI+ SB)'

 

But I don't know how to make 'log' work, because I can't simply digit 'log', it will not allow, it will say 'it was expected: end of instruction' 

 

Sorry about my English, not my first language.

4 Replies

@rawlc 

In VBA, you have to specify multiplication explicitly by using *:

 

... = 1.1665 - 0.07063 * Log(CX + SI + SB)

Hi, thanks for the advising. In fact it work but the final result get wrong no matter what I do, I tried to specify by parentheses the order of the calcule but still didn't work properly.

best response confirmed by allyreckerman (Microsoft)
Solution

@rawlc 

Keep in mind that the Log function in VBA is the natural logarithm (base e = 2.7172...). It corresponds to the worksheet function LN, not to the worksheet function LOG (base 10).

If you need to use the 10-based logarithm, use

 

... = 1.1665 - 0.07063 * Log(CX + SI + SB) / Log(10)

Yes, thank you.