+ Reply to Thread
Results 1 to 11 of 11

Parsing numbers in strings/numbers concatenated together

  1. #1
    Forum Contributor
    Join Date
    11-06-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2007
    Posts
    181

    Parsing numbers in strings/numbers concatenated together

    Hello -

    I need help in parsing out numbers that are contained in strings as well as numbers that need to be seperated
    that are concatenated together. Any help would be appreciated. Attached is a sample file - Column 1 represents before the macro is run and cell B2 reperesents the desired result. I ahve no code to go along with this. My thought was to search for a space and then cast that into an integer.

    Thank you.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-13-2013
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Parsing numbers in strings/numbers concatenated together

    It appears in Cell B2, the numbers and the letters have not been separated and appear exactly the same as they do in Column A. Therefore, I'm not sure what you're trying to accomplish. Can you please clarify?

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing numbers in strings/numbers concatenated together

    You can use these custom functions to accomplish this.

    Please Login or Register  to view this content.

    How to install the User Defined Functions:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook

    The functions are installed and ready to use.


    The function is used in a cell like a normal formula. IN your example workbook you would enter this formula in B1:


    =CreateSortedArray(A1:A6, CHAR(10), 4)

    Explanation:
    =CreateSortedArray(MyRange As Range, Delim As String, SortLen As Long)

    MyRange As Range - the range of cells to evaluate in the formula
    Delim As String - the string that will separate the concatenated values. Char(10) is the text value of a linefeed
    SortLen As Long - how many characters of each string to use for sorting, also how many numbers are used when a long number is split out into individual numbers.
    Attached Files Attached Files
    Last edited by JBeaucaire; 05-27-2014 at 11:44 PM. Reason: Correction to code
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    11-06-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2007
    Posts
    181

    Re: Parsing numbers in strings/numbers concatenated together

    Sure I can clarify.

    Actually I was not too clear on some things.

    First - The numbers and letters haven't been seperated. However, they are out of sequence and I wanted to get them in sequential order according to the numbers.
    Second - One entry needs to be parsed and placed at the top due to the sequence of the numbers.

    Thank you.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing numbers in strings/numbers concatenated together

    Post #3 provides an answer in UDF form that accomplishes the sorting results you demonstrated.

  6. #6
    Forum Contributor
    Join Date
    11-06-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2007
    Posts
    181

    Re: Parsing numbers in strings/numbers concatenated together

    Thank you - I am working on it right now with your solution.

    Looking at it again - I apologize I made some mistakes.

    The results should be (in one cell):

    1497
    1498
    1499 a = a

    ...........and so on.

    Sorry about that.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing numbers in strings/numbers concatenated together

    And your test revealed it actually does that, right? I spotted that error in your example.

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing numbers in strings/numbers concatenated together

    I spotted a tiny error in the code that caused the single numbers to occasionally duplicate. Post #3 above has been updated.

  9. #9
    Forum Contributor
    Join Date
    11-06-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2007
    Posts
    181

    Re: Parsing numbers in strings/numbers concatenated together

    JBeaucaire - Truthfully, I don't really understand how that works, but it does.

    Can I insert a carriage return so in one cell it looks like this:

    1497
    1498
    1499 a = a
    1500 b = b
    1501 c = c
    1502 d = d
    1503 e = e

    maybe its my version of excel but it placed the contents in one line with no spaces.

  10. #10
    Forum Contributor
    Join Date
    11-06-2012
    Location
    New Jersey, US
    MS-Off Ver
    Excel 2007
    Posts
    181

    Re: Parsing numbers in strings/numbers concatenated together

    JBeaucaire - I put it inside of a macro and it executed perfectly! Not sure what I did .

    Thank you very much!!!

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Parsing numbers in strings/numbers concatenated together

    WHen you use it in a cell, you need to format that cell so that it wraps text.

+ 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] Group consecutive numbers in a concatenated list
    By Excel-lecxE in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-15-2018, 11:21 AM
  2. [SOLVED] simple vba formula results in concatenated numbers
    By RJAM99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-28-2014, 05:47 PM
  3. [SOLVED] concatenate two columns of numbers does not produce concatenated value
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-27-2013, 01:50 PM
  4. numbers in concatenated columns not recognised
    By Linden in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-25-2010, 11:23 AM
  5. Sum a range of cells containing numbers with letters concatenated
    By KernelK in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-22-2008, 06:18 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