Consulting

Results 1 to 4 of 4

Thread: Excel not handling large number correctly

  1. #1
    VBAX Newbie
    Joined
    May 2023
    Posts
    2
    Location

    Question Excel not handling large number correctly

    Hi all,

    I have a VBA script that copies a large ID number for product. The ID is split into the, the ID, and the prefix.

    an example is: 54930DEFDEFW4545434I20230502045000000000000002671786

    In this case, the Prefix is the first 20 characters
    54930DEFDEFW4545434I

    and the ID is
    20230502045000000000000002671786

    I have VBA split the string into two using the code:


    x = 54930DEFDEFW4545434I20230502045000000000000002671786
    prefix = Right(x, Len(x) - 20)
    id = Left(x, 20)
    the problem is that excel doesn't seem to be able to handle numbers that long - that when prefix is pasted to a cell, instead of getting
    20230502045000000000000002671786
    I get
    2.02305E+31

    if I change the format to number with zero decimal places, I get
    20230502045000000000000000000000

    its as if Excel cannot handle long number types

    I would change the type to long, however, the ID isn't always numeric, it can also contrain alphabetic characters. so that
    20230502045000000000GTGHT00000000 is also a valid ID

    Is anyone able to help with this?

    thanks in advance.

  2. #2
    in real world, you only need the most 13 digit/sku/pku/ident for your product.
    large number is an exaggeration.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,837
    Location
    Try

    Dim prefix As String
    
    
    prefix = "'" & Right(x, Len(x) - 20)   '    DoubleQuote SingleQuote DoubleQuote 
    
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Newbie
    Joined
    May 2023
    Posts
    2
    Location
    Quote Originally Posted by Paul_Hossler View Post
    Try

    Dim prefix As String
    
    
    prefix = "'" & Right(x, Len(x) - 20)   '    DoubleQuote SingleQuote DoubleQuote 
    
    

    thank you - that worked

Tags for this Thread

Posting Permissions

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