Macro Returns Only 15 Digits

  • I am using Excel 2003. I am trying to importing a 20 character from a barcode scanner to cell K2 in an Excel spreadsheet. When the part is scanned, the program handling the scanner data shows the data as being 12345678901234567890 . I am running a macro that retrieves that data and places it in cell K2. The number that appears in cell K2 is 12345678901234500000 . The macro module code reads:


    I am guessing that one of the Dim statements has the wrong word after As but nothing I have tried gets me past this point. I am not above offering a bribe for an answer! :)

  • Re: Macro Module Only Returns 15 Of 20 Digits


    Hi,


    This sounds like a result of Excel's limitations. If you look in the Help files for Excel and look at Calculation Specifications the number precision is indicated as being 15 digits.


    Not sure if this will work but have you tried importing the data as a string data type?

  • Re: Macro Module Only Returns 15 Of 20 Digits


    Is the string class normally used to bring in text? I would like to have those 20 digits treated as text, if that is possible. When I declare certain variables as strings, the number that appears in K2 is in scientific notation form. When I try to change the cell format to text, the sample shown in the window is also in scientific notation. Good ol' Mr. Gates!

  • Re: Macro Module Only Returns 15 Of 20 Digits


    try replacing this:

    Code
    Range("K2").Value = WedgeData(1)


    with this:

    Code
    Range("K2").Value = Cstr(WedgeData(1))
  • Re: Macro Module Only Returns 15 Of 20 Digits


    Hi


    Does this amendment work? I believe this was what Richie was recommending:



    Richard

  • Re: Macro Returns Only 15 Digits


    Comrades,
    Thanks to all of you who went to the effort to try and help me with this problem. The problem has been solved and I thought to let you know how we got around the problem. It appears that when Excel sees strings over 15 characters that consist of only numbers, it treats it as a number regardless of the variable type declaration. So, we placed an * into the 21st digit of the incoming data. This forced Excel to treat the incoming data as a string and the world was once again, a happy place. FYI, I was not the one who came up with the solution. :)
    Thanks again for all the help!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!