+ Reply to Thread
Results 1 to 9 of 9

Convert Numbers to Strings - Need Formula

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Convert Numbers to Strings - Need Formula

    Hi All,

    I need to convert imported alpha-numeric product codes to strings.

    Where the code contains a letter or other symbol, that is trivial, since it will already be a string.

    However, where the code is numeric, I am having trouble.

    The codes come in as an export into excel from another system. Unfortunately, there is no way to specify that the export comes in as a text string (setting cells to TEXT format would be an example of this, but it doesn't work in this scenario).

    I am then referencing the import, and need a formula that takes the codes, and converts to strings, so for example, I have tried:

    =Text(A1,"General")

    This works on most items, but where the code is a long numeric (e.g. 432200697940) the formula returns "4.32201E+11", whereas I need "432200697940".

    I then tried:

    =Text(A1,"0")

    This works on the above example, but it converts 500.12 into "500" which is no good.

    If I use:

    =Text(A1,"0.00")

    then it converts 800 into "800.00" so that's no good either.


    Can anyone tell me a format code that will work?

    Thanks,

    Alan.

  2. #2
    Registered User
    Join Date
    12-04-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Convert Numbers to Strings - Need Formula

    Hi All,

    After typing the above (possibly DUE to typing the above), I had an idea, and it appears it works:

    =IF(ISNUMBER(B2),IF(B2=INT(B2),TEXT(B2,"0"),INT(B2)&MID(B2,LEN(B2)-LEN(INT(B2)),999)),B2)

    It lacks elegance, but I think it covers all cases.

    Any comments (or improvements)?

    Thanks,

    Alan.

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Convert Numbers to Strings - Need Formula

    Also check this...

    A
    B
    1
    Your Data Formula Result
    2
    500.12
    =TEXT(A2,IF(LEN(A2)-LEN(INT(A2)),"#."&REPT("#",LEN(A2)-LEN(INT(A2))),"#"))


    A
    B
    1
    Your Data Formula Result
    2
    500.12
    500.12


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    12-04-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Convert Numbers to Strings - Need Formula

    Hi SixthSense,

    Yep. Actually, mine contains an error, but I think this fixes it:

    =IF(ISNUMBER($B2),IF($B2=INT($B2),TEXT($B2,"0"),INT($B2)&MID($B2,LEN(INT($B2))+1,999)),$B2)

    Not sure if this is exactly logically equivalent to yours though?

    Alan.

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,937

    Re: Convert Numbers to Strings - Need Formula

    =A1&""
    TRY THIS, I am not sure just trail
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Convert Numbers to Strings - Need Formula

    Quote Originally Posted by Alan3285 View Post
    Not sure if this is exactly logically equivalent to yours though?
    Your's is a better one

  7. #7
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,937

    Re: Convert Numbers to Strings - Need Formula

    modification to your formula
    =IF(ISNUMBER($B2),INT($B2)&MID($B2,LEN(INT($B2))+1,999),$B2)

  8. #8
    Registered User
    Join Date
    12-04-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Convert Numbers to Strings - Need Formula

    Quote Originally Posted by nflsales View Post
    =A1&""
    TRY THIS, I am not sure just trail
    {Buries head in hands and weeps}

    I'll check too, but it looks good to me so far....

    Alan.

  9. #9
    Registered User
    Join Date
    12-04-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: Convert Numbers to Strings - Need Formula

    Hi All,

    Just confirming that I have not found any example where nflsales solution fails, so I am marking this thread as solved.

    Thanks,

    Alan.

+ 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. [SOLVED] all possible formula needed to convert text numbers to numbers
    By JEAN1972 in forum Excel General
    Replies: 5
    Last Post: 07-21-2014, 01:20 PM
  2. excel formula to search Multiple strings in several columns and return strings
    By krratna123 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-13-2013, 11:20 AM
  3. Replies: 1
    Last Post: 08-13-2013, 08:32 AM
  4. Convert ASCII Character strings into HEX Strings
    By Chris Mathers in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-13-2010, 12:25 PM
  5. [SOLVED] Convert formula to Numbers
    By msw in forum Excel General
    Replies: 1
    Last Post: 01-15-2005, 11:06 PM

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