+ Reply to Thread
Results 1 to 5 of 5

Excel 2007 : How to split data in a cell at every 16th character

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    5

    How to split data in a cell at every 16th character

    I have a range of data in column d in in a spreadsheet. The length if the data in each column varies but i would like to split the data at every 16th character. I know i can do the via the text to columns function but i would prefer to run a macro to do this as i can have in excess of 3000 rows and some rows have more than 600 characters.

    A sample of a row is below:

    DRSPROF CLIEPROF 12111 DUNCPROF 12114 ARISPROF

    What i would like is for the split to occur before the "C" in CLIEPROF, before the "D" in DUNCPROF and before the "A" in ARISPROF. So for the above string there is 56 characters and i would like to split it every 16th character. Another row might have 128 character but i would still like to split every 16th character. Can anyone suggest how i have do this?

    I have tried the split function with the code below but i don't know how to fill the array with the text 1-16 and so on etc....
    Please Login or Register  to view this content.
    Thanks Ian
    Last edited by arlu1201; 04-24-2012 at 08:17 AM. Reason: Please put code tags in future.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: How to split data in a cell at every 16th character

    DRSPROF CLIEPROF 12111 DUNCPROF 12114 ARISPROF

    The 16th characters are highighted. I have included the spaces in the count. But your calculation of the 16th character doesnt match with mine. How is it so?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Expert
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    1,312

    Re: How to split data in a cell at every 16th character

    Hi check such code and tell me is it ok?
    Please Login or Register  to view this content.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  4. #4
    Registered User
    Join Date
    04-24-2012
    Location
    Scotland
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: How to split data in a cell at every 16th character

    Thanks Tom. This is exactly what i was looking for and hadn't even thought of using the MID function. I commented out the line - Columns("b:c").Clear as i have other data in these columns and amended line - For Each c In Columns(1).SpecialCells(2) to - For Each c In Columns(4).SpecialCells(2) as my data is in column D.

    Your help is much appreciated.

    arlu1201 - it looks like the spaces in between the text hasn;t copied over. Thanks for your time.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: How to split data in a cell at every 16th character

    A way without using VBa.
    With your data in Column A beginning Row 2 down
    In B2
    Please Login or Register  to view this content.
    Drag Down as required
    In C2
    Please Login or Register  to view this content.
    Drag across as required, then Down

    Are you sure your data splits every 16 characters?
    I think you might have cumulative errors on longer strings.

    [Edit] Okay, this should work.
    When pasting directly to the forum, strings are automatically trimmed of what it considers "extra" spaces.
    If you put your sample string in code tags, these spaces will not be trimmed.

    See this workbook
    Attached Files Attached Files
    Last edited by Marcol; 04-24-2012 at 09:48 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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