+ Reply to Thread
Results 1 to 20 of 20

Splitting text in cells.

  1. #1
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Splitting text in cells.

    Hi,

    I need a script that would break up a block of text in a cell at full stops, question marks, and exclamation marks, and create additional cells (not rows) shifting bottom cells down and inserting split sentences consecutively into created cells.

    So, for example,

    A1 Sentence 1. Sentence 2? Sentence 3!
    A2 Sentence 4.

    Should become:

    A1 Sentence 1.
    A2 Sentence 2?
    A3 Sentence 3!
    A4 Sentence 4.

    Could someone help me with this, please?

    Thanks in advance.

    PS:
    Also asked here (no working solutions so far):
    https://www.mrexcel.com/forum/excel-...ext-cells.html

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Splitting text in cells.

    Try this
    Enter formula in B1 and copy down
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    v A B
    1 Sentence 1. Sentence 2? Sentence 3! Sentence 1.
    2 Sentence 4. Sentence 2?
    3 Sentence 3!
    4 Sentence 4.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Splitting text in cells.

    Nice formula Al,

    Let me add simple (easy to read, understand and modify, but not quick for longer datasets) VBA solution, as the question was published in programming/VBA/macros subforum:

    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Splitting text in cells.

    Please Login or Register  to view this content.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting text in cells.

    Well, it works on your sample:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting text in cells.

    Why not
    Please Login or Register  to view this content.
    Last edited by PCI; 06-26-2018 at 02:03 PM.
    - Battle without fear gives no glory - Just try

  7. #7
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Splitting text in cells.

    Thank you for your effort, guys, but NONE of the above work.

    AlKey
    I don't need a formula. The replacement should happen in the same column starting with the same cell (first sentence should remain in the selected cell with all other sentences moved to the cells created for them below).

    Kaper, PCI
    Your code splits cells below the selected cell as well.

    Mr.PB
    Your code discards everything after the 256th character.

    xladept
    Your code does nothing with the selected cell but splits the one below and corrupts it into the bargain.
    Last edited by Saighead; 06-26-2018 at 02:18 PM.

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Splitting text in cells.

    Perhaps can you try the last update done in my code
    Keep in mind to adjust the list of chararcters to use => Chlst
    Please Login or Register  to view this content.
    Last edited by PCI; 06-26-2018 at 02:09 PM. Reason: ScreenUpdating statement added

  9. #9
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Splitting text in cells.

    PCI
    Nope, doesn't work right this time, either. Still splits not only the selected cell but the ones below as well.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting text in cells.

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  11. #11
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Splitting text in cells.

    xladept

    Take any text (newspaper article, novel, anything). Paste a paragraph each into cells A1:A10 or any other range. I need a script that would split text in ANY selected cell into sentences (ending in .?! minus all leading & trailing spaces) without affecting ANY other neighboring cells... What need is there to upload a sample workbook?
    Last edited by Saighead; 06-26-2018 at 03:57 PM.

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Splitting text in cells.

    This requires that you select the first cell:

    Please Login or Register  to view this content.
    Last edited by xladept; 06-26-2018 at 04:03 PM.

  13. #13
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Splitting text in cells.

    Re: What need is there to upload a sample workbook?
    I guess you don't really want any help.

  14. #14
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,602

    Re: Splitting text in cells.

    ... What need is there to upload a sample workbook?

    Why are you asking for members to provide their own sample data and the solution?

    Want to get your question answered quickly?
    • Ensure your question is not too vague. Don't assume anyone is familiar with your problem. While you can upload small attachments, describe your problem in the body of the post. We are fortunate to have several Excel gurus, but few mind-readers.
    • On the other hand, skip irrelevant details. Be descriptive and concise. Short, direct, and to-the-point questions with apt thread titles are almost always answered promptly.
    • Keep the scope reasonably narrow. Questions like, "How do I set up an accounting system in Excel?" might be a long time waiting.
    • Explain what you've already tried. ("Calculation is set to automatic, but formulas still don't compute") so helpers don't waste your time or theirs.
    • Post a WORKBOOK. Nobody wants to type data from a picture or paste text from your post into a spreadsheet as a prelude to helping. To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.
    • If your question has not been answered within a day, consider adding another post with any additional information you believe is relevant. If you think your post is good as is, just reply to your own thread with the words "Bump no response", which will bring it to the top of the forum.
    Last edited by protonLeah; 06-26-2018 at 04:20 PM.
    Ben Van Johnson

  15. #15
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Splitting text in cells.

    Fixed!

    Please Login or Register  to view this content.

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,517

    Re: Splitting text in cells.

    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Splitting text in cells.

    Mr.PB

    Thank you so much! I was starting to think about giving it up as a bad job... Yours is the only working solution. The only thing is that your code inserts a blank cell after the last segment and leaves leading spaces. Nothing major, easily fixable manually but is it possible to work these things out in the script?

  18. #18
    Registered User
    Join Date
    06-26-2018
    Location
    USA
    MS-Off Ver
    2016
    Posts
    22

    Re: Splitting text in cells.

    Sure! I intentionally left the spaces to get the character count correct. Here's a version that leaves no trailing or leading spaces.

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    05-17-2013
    Location
    St. Petersburg
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: Splitting text in cells.

    @Mr.PB

    Excellent! Exactly what I had in mind. Thanks again, I really appreciate your help, your script just saved me a world of hassle.

  20. #20
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,705

    Re: Splitting text in cells.

    Violation removed. I was responding to a report, but missed the link in the first post. My apologies.
    Last edited by 6StringJazzer; 06-27-2018 at 04:41 PM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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] Splitting Text from cells
    By pauldaddyadams in forum Excel General
    Replies: 6
    Last Post: 11-26-2015, 07:06 AM
  2. Splitting text content into one cell into three cells
    By Adie Vienings in forum Excel General
    Replies: 2
    Last Post: 08-12-2013, 07:06 AM
  3. [SOLVED] Splitting text from one cell into separate text fragments, Located in adjacent cells
    By onsid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2013, 08:32 PM
  4. [SOLVED] Splitting Text into multiple cells
    By justin3681 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-21-2012, 03:36 PM
  5. splitting text into separate cells
    By kristygrippo in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-24-2009, 05:54 PM
  6. splitting a text into two cells
    By pmreji in forum Excel General
    Replies: 8
    Last Post: 11-25-2006, 09:33 AM
  7. [SOLVED] splitting and rejoining text in cells
    By sh0t2bts in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-26-2005, 02: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