+ Reply to Thread
Results 1 to 16 of 16

Split a sentence into specifi number of words as defined

  1. #1
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Split a sentence into specifi number of words as defined

    Hi All,

    request you to please help on my request.

    For example below sentence : i want it to break it to 4 word's each (similar to bigram, trigram.. i need 4gram), also need an option where i can input specific number of words to be split into cells.

    Ex : I feel very fortunate to be part of to be part of of the company for the great opportunities it offers and it would make me feel good that friends or colleagues can be part of what I am now

    need as : I feel very fortunate
    to be part of
    of the company for the
    great opportunities it offers

    ............and so on into adjacent cells 4 words each split.

    i have millions of rows, i am trying to make a meaningful word cloud for sentiment analysis viz.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Re: Split a sentence into specifi number of words as defined

    Good morning rincyroyal

    Use the Text to Columns functionality under the Data tab.
    Set the delimiting character to a space.
    This will put each word in your sentence in its own column, them you can use the CONCATENATE formula (or &) to add combine four columns at a time , thus :
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Split a sentence into specifi number of words as defined

    Quote Originally Posted by rincyroyal View Post
    i have millions of rows
    Given that a single sheet only holds just over 1 million rows, I somehow doubt that your claim is correct. Using excessive exaggeration to describe your problem is not helpful to anyone trying to help you.

    With your text in A1, enter this regular formula in B1

    =LEFT(A1,FIND("|",SUBSTITUTE(A1," ","|",4))-1)

    and this Array formula in C1

    =IF(B1="","",LEFT(REPLACE($A1,1,SUM(LEN($B1:B1),COUNTA($B1:B1)),""),IFERROR(FIND("|",SUBSTITUTE(REPLACE($A1,1,SUM(LEN($B1:B1),COUNTA($B1:B1)),"")," ","|",4))-1,LEN($A1))))

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    Once array confirmed, drag right and fill down as needed.

  4. #4
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    Thanks you all for the quick solutions, truly appreciate you r quick responses, will try and test

  5. #5
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Split a sentence into specifi number of words as defined

    Hi,

    Another way, also assuming your data in A1, in B1 copied across and down as far as needed:

    =IF(COLUMNS($B1:B1)>ROUNDDOWN((LEN($A1)-LEN(SUBSTITUTE($A1," ","")))/4,0)+1,"",TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A1," ",REPT(" ",LEN($A1)),COLUMNS($B1:B1)*4),LEN($A1)))," ",REPT(" ",LEN($A1)),MAX(4,COLUMNS($B1:B1)*4-4)),LEN($A1))))

    Refer to attached sample.
    Attached Files Attached Files
    Last edited by jtakw; 08-03-2018 at 10:19 PM.

  6. #6
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Split a sentence into specifi number of words as defined

    Adding one more option for 2 separate formulas for B2 and C2 across:

    Assuming your data in A2, in B2, enter and copied down.

    =LEFT(A2,FIND("^",SUBSTITUTE(A2," ","^",4))-1)

    Then, in C2, enter and copied across and down.

    =TRIM(LEFT(SUBSTITUTE(MID($A2,SUMPRODUCT(LEN($B2:B2))+COLUMNS($B1:B1)+1,255)," ",REPT(" ",LEN($A2)),4),LEN($A2)))

    Both methods from my Post #5 and this one included in new attached sample.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    10-30-2003
    Location
    Singapore
    MS-Off Ver
    Excel 2019
    Posts
    197

    Re: Split a sentence into specifi number of words as defined

    Or try this shorter formula.

    1] Assume your data put in A1

    2] In B1, enter formula and copied across until blank

    =TRIM(MID(SUBSTITUTE(" "&$A1," ",REPT(" ",300)),(4*COLUMNS($A:A)-3)*300,1200))

    Regards
    Bosco
    Attached Files Attached Files
    Last edited by Bosco; 08-04-2018 at 03:03 AM.

  8. #8
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    AWESOME.. !! this is what i wanted...!

    now i can define what i want.

  9. #9
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    thank you all masters..!

  10. #10
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Split a sentence into specifi number of words as defined

    Quote Originally Posted by rincyroyal View Post
    AWESOME.. !! this is what i wanted...!

    now i can define what i want.
    You're welcome, glad it works for you.

    Add rep would be appreciated, click the "Star" at the lower left corner of the posts you found helpful.

    If your query has been "Solved", please mark the thread as such, Thank you.

  11. #11
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    Sorry for the delayed response, surely will do that.

    However i have a request within the solution, how do i increase the sentence word count, for instance this formula which you gave :
    =TRIM(MID(SUBSTITUTE(" "&$A1," ",REPT(" ",300)),(4*COLUMNS($A:A)-3)*300,1200)) splits by 4 words, how can i increase to 5, 6..etc, also decrease by 3,2, etc.

    Request you to please add a little explanation.

  12. #12
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Split a sentence into specifi number of words as defined

    Hi rincyroyal,

    You had quoted my formulas in a previous response (looks like MODs deleted it), your latest question in Post #11 is Not my formula.

    If you want the flexibility of changing the requirement from 4 to 5, or 3, or 7, or whatever number of words you want separated, I suggest using a Cell reference rather than "hard-coding" the requirement in the formulas.

    A6 is the Cell Reference which contains the number for the "Word count" requirement.

    Single formula for All columns, data in A3, formula in B3 and copied across as far as needed:

    =IF(COLUMNS($B3:B3)>ROUNDDOWN((LEN($A3)-LEN(SUBSTITUTE($A3," ","")))/$A$6,0)+1,"",TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A3," ",REPT(" ",LEN($A3)),COLUMNS($B3:B3)*$A$6),LEN($A3)))," ",REPT(" ",LEN($A3)),MAX($A$6,COLUMNS($B3:B3)*$A$6-$A$6)),LEN($A3))))

    2 formula option, data in A4, formula in B4:

    =LEFT(A4,FIND("^",SUBSTITUTE(A4," ","^",$A$6))-1)

    Then, formula in C4 and copied across as far as needed

    =TRIM(LEFT(SUBSTITUTE(MID($A4,SUMPRODUCT(LEN($B4:B4))+COLUMNS($B3:B3)+1,255)," ",REPT(" ",LEN($A4)),$A$6),LEN($A4)))

    I've included these updated formulas using a Cell Reference in my attachment below, Rows 1 and 2 are the original formulas, Rows 3 and 4 are the new ones.

    Review them, try them out, let me know if you have further questions.
    Attached Files Attached Files
    Last edited by jtakw; 08-08-2018 at 07:30 PM.

  13. #13
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    Excellent Solution. It WORKS MORE than what i NEEDED..!

  14. #14
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    Hi Master, i get a new error, perhaps i was not clear in the requirement, sorry about that.

    The formula returns error when the cell contains less number of words than the inputted/reference cell number (considered to split)

  15. #15
    Registered User
    Join Date
    08-22-2014
    Location
    india
    MS-Off Ver
    2016
    Posts
    23

    Re: Split a sentence into specifi number of words as defined

    splitcell.png

    Please find the reference

  16. #16
    Valued Forum Contributor jtakw's Avatar
    Join Date
    05-05-2018
    Location
    CA, USA
    MS-Off Ver
    2016
    Posts
    668

    Re: Split a sentence into specifi number of words as defined

    Quote Originally Posted by rincyroyal View Post
    Hi Master, i get a new error, perhaps i was not clear in the requirement, sorry about that.

    The formula returns error when the cell contains less number of words than the inputted/reference cell number (considered to split)
    The other formulas provided previously already handles these situations, so this is the only one that needs tweaked.
    Just update that formula to this:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    It'll work for Any number of words, even 1
    Last edited by jtakw; 08-09-2018 at 05:52 PM.

+ 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. Split up a sentence in parts, without spliting up words.
    By Dubrock in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-23-2016, 07:31 AM
  2. split the sentence in to four parts
    By saravanan1981 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-22-2015, 04:56 AM
  3. Replies: 4
    Last Post: 11-11-2015, 03:00 PM
  4. Help! Count how many words in a sentence match a dictionary of words
    By sonyaelis in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-06-2013, 05:31 AM
  5. [SOLVED] Match a data entry sentence with the highest number of common words within a database
    By jasonbwt in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 08-13-2012, 01:17 AM
  6. Replies: 2
    Last Post: 05-06-2011, 09:14 AM
  7. Split words with number under one cell
    By Kenji in forum Excel General
    Replies: 5
    Last Post: 04-20-2010, 06:56 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