+ Reply to Thread
Results 1 to 6 of 6

Splitting a long field into two without chopping words

  1. #1
    Forum Contributor
    Join Date
    04-03-2009
    Location
    Anchorage, Alaska, USA
    MS-Off Ver
    Office 365
    Posts
    113

    Splitting a long field into two without chopping words

    Hi,

    Sample workbook attached.

    I'm trying to take one long field, like a street address, and split it into fields. These fields can hold only so many characters. The trick is I do not want to split words, so if the default split is going to split a word in two, then I need to find the space before the default split, so I can split there instead.

    Can this be done by formula. Or is this a macro situation?

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    02-10-2019
    Location
    Georgia, USA
    MS-Off Ver
    Office 365
    Posts
    2,873

    Re: Splitting a long field into two without chopping words

    Maybe

    F3 and copied down:
    =IF(LEN(A3)>20,TEXTBEFORE(LEFT(A3,20)," ",-1,,1),A3)

    G3 and copied down:
    =TEXTAFTER(A3,F3)

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Splitting a long field into two without chopping words

    Delete ALL expected results in F and G, then in F3:

    =LET(a,IF(LEN(A3:A7)>20,TEXTBEFORE(LEFT(A3:A7,20)," ",-1,,1),A3:A7),b,BYROW(A3:A7,LAMBDA(r,TEXTAFTER(r,a))),HSTACK(a,b))
    Attached Files Attached Files
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,631

    Re: Splitting a long field into two without chopping words

    Try
    In L3
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  5. #5
    Forum Contributor
    Join Date
    04-03-2009
    Location
    Anchorage, Alaska, USA
    MS-Off Ver
    Office 365
    Posts
    113

    Re: Splitting a long field into two without chopping words

    Greg, nice! Ali, nice! KV...I dont know what to tell you - that's some next-level Gandalf wizardry going on there. Nice!

    TLDR for anyone who wants the answer: They all work!

    Greg: I just heard of TEXTBEFORE/TEXTAFTER moments before I wrote this question, and I was definitely making things too complicated for my own good. I didn't know these formulae could be manipulated in the way they could be with the extra arguments as you are showing me here. But I can read your formulae left-to-right, and they make sense now. Thank you!

    Ali: I was going more in your direction with evaluating LET and so on, but I quickly drove myself into the weeds. I didnt know you could array LEN and LEFT and such. LEN(A1) was as range-y as I ever got. LEN(A3:A7) and LEFT(A3:A7...) - mind blown! I recall that for a brief moment months ago I understood LAMBDA and HSTACK and BYROW. I havent used those for a while and actually forgot they existed. They deserve my study. Thank you!

    KV: You live in a tall wizard's tower high above the land, don't you? I'll make sense of what you did eventually. But as soon as I saw the opposing formulae TEXTSPLIT and TEXTJOIN side-by-side I knew right then that I was in deep, deep waters. It's a beautiful composition. Thank you so much!
    Last edited by akedm; 04-09-2024 at 03:32 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,730

    Re: Splitting a long field into two without chopping words

    Just as an aside, KV's formula is not as efficient as mine and COULD fall over if the dataset grew very large.

    Thanks for the rep.

+ 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. How do I display lat-long coordinates when splitting cells
    By Videoman22 in forum Excel General
    Replies: 14
    Last Post: 09-16-2023, 06:30 PM
  2. Splitting a long text by words not characters
    By Stwong in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-09-2015, 10:17 PM
  3. [SOLVED] looking formula for Extract Specific WORDs in existing LONG Words
    By santosh226001 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-07-2013, 08:21 AM
  4. Splitting data in one long row into multiple rows
    By karisharp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 07:16 PM
  5. Splitting data in one long row into multiple rows
    By karisharp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2013, 01:18 PM
  6. Splitting Long Strings
    By moericus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-07-2008, 04:09 PM
  7. Splitting Long Line
    By Dale in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2005, 10:06 AM

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