+ Reply to Thread
Results 1 to 6 of 6

Log10 Error using Office 2016

  1. #1
    Registered User
    Join Date
    10-10-2003
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    88

    Log10 Error using Office 2016

    We have the need to round the contents of various different cells to 3 significant figures. For the sake of this discussion lets use a value of 0.7567 that is in range A1

    If we use the following to set the value of a cell to 3 decimal places in a sheet, the line does just what we want (rounds any number to 3 sig figs.):

    = ROUND(A1, 3 - (1 + INT(LOG10(ABS(A1))))) -----> This works great in a sheet.

    If we use the next line of code:

    Please Login or Register  to view this content.
    The numeral 3 in the code above is for significant figures.

    Using this line of code in VBA we get the following error: Compile error: Sub or function not defined and Log10 is highlighted as the cause of the error. It appears Log10 doesn't work in VBA.
    If anyone has an idea how we could get this line of code to work in VBA, it would be greatly appreciated.

    This table shows an example of how we deal with significant figures.

    Starting Value Value need from starting value
    0.7567 0.757
    1.7567 1.76
    10.7567 10.8
    100.7567 101
    1075.7567 1080
    10757.7567 10800
    107576.7567 108000


    Thanks for looking, and we appreciate any help!!!!

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Log10 Error using Office 2016

    Two ways:

    A
    B
    C
    D
    1
    0.7567
    0.757
    0.757
    B1: =--TEXT(A1, "0.00E+0")
    2
    1.7567
    1.76
    1.76
    C1: =SigDig(A1, 3)
    3
    10.7567
    10.8
    10.8
    4
    100.7567
    101
    101
    5
    1075.7567
    1080
    1080
    6
    10757.7567
    10800
    10800
    7
    107576.7567
    108000
    108000


    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,819

    Re: Log10 Error using Office 2016

    There is no VBA function log10() -- that is an Excel function.

    You can use Excel worksheet functions in VBA through the WorksheetFunction object: https://msdn.microsoft.com/en-us/vba...n-visual-basic
    VBA has the natural log built into its Log() function. If you recall your "change of base" rules for logarithms (http://www.purplemath.com/modules/logrules.htm ), then it should be easy to develop the formula to get log base 10 using the natural log function.

    If you are interested in a different approach, I stumbled upon a "text" approach that looks something like this:
    Excel functions: =VALUE(TEXT(A1,"0.00E+0")). If one wanted to tackle a variable number of sig figs, it would be easy to build the number format code using the REPT() function. If Excel decides to default to a scientific format, format the cell with a suitable number format.
    VBA newvalue=CDbl(Format(oldvalue,"0.00E+0")). Again, if you want it to be variable, you just figure out the text function that builds the number format code.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Log10 Error using Office 2016

    Hi Captain,

    The log is negative so this rounds to four places:

    Please Login or Register  to view this content.
    *so .7567 is unaltered
    Last edited by xladept; 03-09-2018 at 03:27 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Log10 Error using Office 2016

    Note Log10(x) = Log(x)/Log(10)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    10-10-2003
    Location
    Massachusetts
    MS-Off Ver
    Office 365
    Posts
    88

    Re: Log10 Error using Office 2016

    We used shg's function and the following code to make all numbers display properly.
    Thanks to all for you help and ideas!!!!!!!!!!!!!!!!!!!!


    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Office 2016 project error on opening
    By dfrimmel in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-25-2017, 10:30 AM
  2. Replies: 0
    Last Post: 08-06-2017, 01:48 AM
  3. Replies: 1
    Last Post: 12-18-2016, 11:47 PM
  4. Replies: 1
    Last Post: 08-07-2016, 05:52 PM
  5. [SOLVED] Code not working in Office 2010 and Office 2016
    By amitmodi_mrt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2016, 02:48 PM
  6. Replies: 2
    Last Post: 05-24-2016, 10:43 PM
  7. VBA error 3706 connecting SQL Azsure Office 2016
    By LotusElise in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-28-2015, 10:46 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1