+ Reply to Thread
Results 1 to 31 of 31

Generate (concat) sentences from three columns - each column has multiple words in one cel

  1. #1
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Generate (concat) sentences from three columns - each column has multiple words in one cel

    I have an excel sheet.

    Column B1 has a horizontal list of words (people) separated by strings in the same cell.
    Column C1 has a horizontal list of words (verbs) separated by strings in the same cell.
    Column D1 has a horizontal list of words (places) separated by strings in the same cell.

    I would like to iterate through and create sentences.
    Example: My daughter is playing football in the garden.

    a. I would like to produce 100 sentences by concatenating one word from each column.
    b. The sentences should not be the same unless it's unavoidable.

    I have tried this formula but it doesn't work on my macbook pro (things never do that's why I'm here.

    =INDEX(SPLIT(B1, ","), RANDBETWEEN(1, COUNTA(SPLIT(B1, ",")))) & " " &
    INDEX(SPLIT(C1, ","), RANDBETWEEN(1, COUNTA(SPLIT(C1, ",")))) & " " &
    INDEX(SPLIT(D1, ","), RANDBETWEEN(1, COUNTA(SPLIT(D1, ","))))
    Attached Files Attached Files
    Last edited by codeBeast; 05-13-2023 at 02:23 AM. Reason: update the excel

  2. #2
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,368

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    The file that you attach is blanks no data there

  3. #3
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    ^^ same as above ^^
    If things don't change they stay the same

  4. #4
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Really sorry.
    Last edited by codeBeast; 05-13-2023 at 02:23 AM.

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    We see #REF! errors now, maybe you need to save the data as values before uploading. You can also update your original post with the file and just let us know you have updated that. That way there will not be lots of files through the post.

  6. #6
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Yes, you were right. I have saved the data as values. I have also updated the excel.
    Attached Files Attached Files

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    I'm a bit confused. What is the SPLIT function? Is this a Googlesheets question?
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  8. #8
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Ah OK. I think it's a javascript function. In excel I was googling and found TEXTSPLIT. I still can't get it to work.
    I mean I don't have to use TEXTSPLIT, if there is another way of doing this.

  9. #9
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    is 16.37 for Mac a version of the Product: O365 for Mac or something else? I have no idea what 16.37 means....

  10. #10
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Yes, it's the excel version for mac - Microsoft 365 subscription. Released May 12, 2020.

  11. #11
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    With TEXTSPLIT

    =TRIM(REDUCE("",B2:D2,LAMBDA(a,v,VSTACK(TOCOL(a&" "&TEXTSPLIT(v,","))))))

    Without TEXTSPLIT

    =LET(z,B2:D2,l,LEN(z),n,l-LEN(SUBSTITUTE(z,",",))+1,p,PRODUCT(n),s,SEQUENCE(p,,0),m,MOD(INT(s/p*INDEX(n,1)*INDEX(n,2)^{0,1,1}*INDEX(n,3)^{0,0,1}),n),
    t,TRIM(MID(SUBSTITUTE(z,",",REPT(" ",l)),m*l+1,l)),INDEX(t,,1)&" "&INDEX(t,,2)&" "&INDEX(t,,3))
    Attached Files Attached Files
    Last edited by Bo_Ry; 05-13-2023 at 09:30 AM.

  12. #12
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    I took a slightly different approach. Instead of returning ALL possible sentences, this returns n sentences (selected in cell B4), chosen randomly from all possible selections. A new selection can be made by changing the seed number in B5 (any integer 1-1,000,000).

    Certainly not as neat as Bo_Ry's effort, but here it is, for what it's worth!

    =LET(Seed,B5,N,B4,A,TEXTSPLIT(B2,,","),B,TEXTSPLIT(C2,,","),C,TEXTSPLIT(D2,,","),D,ROWS(A),E,ROWS(B),F,ROWS(C),G,SEQUENCE(D*E*F)-1,H,INDEX(A,1+INT(G/(E*F)))&" "&INDEX(B,1+MOD((1+INT(G/F))-1,E))&" "&INDEX(C,1+MOD(G,F)),I,MOD((B5+G)/PI(),1),INDEX(H,MATCH(LARGE(I,SEQUENCE(B4)),I,0)))
    Attached Files Attached Files
    Last edited by Glenn Kennedy; 05-13-2023 at 12:22 PM.

  13. #13
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Wow - Bo_ry and Glenn those were amazing - well beyond my knowledge base.
    Right now I will use Bo_rys: =TRIM(REDUCE("",B2:D2,LAMBDA(a,v,VSTACK(TOCOL(a&" "&TEXTSPLIT(v,","))))))
    because it's so short and works perfectly.

    All that's left to do is sort the sentences. I am trying to use the sort dialogue box but it "order by" it won't let me type in a custom list.

    I just need to sort the sentences into unique as in: Person + verb phrases: are as unique as possible.
    example:
    My dangerous daughter is writing a letter in the river.
    My sunny son is reading a book in the mountain.
    My mum is singing a song etc...

    It's so the sentences are as unique as possible. Most of these are repeated mainly because I am building an education platform for foreign kids in Spain and repetition is how they learn.

  14. #14
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    You're welcome.



    It would be very nice if you were to just click the Add Reputation button at the foot of any of the posts of members who helped you reach a solution.

    Finally, if that takes care of your original question, please click on "Thread Tools" from the menu link (just above the first post in the thread) and mark this thread as SOLVED.

  15. #15
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Hi Glen, yes I usually do that - I was just waiting for the last part or do I mark this one as solved then create a new post re: they sorting? btw just added the reputation points and will mark this post as solved. THANKS.

  16. #16
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    No need for a new thread. However, I must have misundeestood the requirement.

    Mine generates n unique sentences, where you define n.

    If that's not what you want... you'll have to explain again.

  17. #17
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    No duplicates for 7 Places

    =LET(z,B2:D2,d,DROP(REDUCE(0,z,LAMBDA(a,v,LET(t,TEXTSPLIT(v,,","),r,ROWS(t),HSTACK(a,VSTACK(r,SORTBY(t,RANDARRAY(r))))))),,1),
    m,TAKE(d,1),BYROW(INDEX(d,MOD(SEQUENCE(MIN(m),,0),m)+2,SEQUENCE(,COLUMNS(d))),LAMBDA(c,TEXTJOIN(" ",,c))))


    No duplicates for 16 verbs
    Some duplicates for 16-12 = 4 people and 16-7 = 9 Places

    =LET(z,B2:D2,d,DROP(REDUCE(0,z,LAMBDA(a,v,LET(t,TEXTSPLIT(v,,","),r,ROWS(t),HSTACK(a,VSTACK(r,SORTBY(t,RANDARRAY(r))))))),,1),
    m,TAKE(d,1),BYROW(INDEX(d,MOD(SEQUENCE(MAX(m),,0),m)+2,SEQUENCE(,COLUMNS(d))),LAMBDA(c,TEXTJOIN(" ",,c))))
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Glenn, please forgive me - I opened Bo_ry's first and it worked and the formula was short, I just used it and stuck with it. I have just tried yours and it's pretty great too.

    Bo_ry - this new one works even better for me but it only generates 16 sentences. How do I generate "n" amount. I need about 1000.
    I changed the values in the boxes but I have an error. Then I realised those numbers are the elements in each array.

  19. #19
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Try

    =LET(z,B2:D2,d,DROP(REDUCE(0,z,LAMBDA(a,v,LET(t,TEXTSPLIT(v,,","),r,ROWS(t),HSTACK(a,VSTACK(r,SORTBY(t,RANDARRAY(r))))))),,1),
    m,TAKE(d,1),BYROW(INDEX(d,MOD(SEQUENCE(100,,0),m)+2,SEQUENCE(,COLUMNS(d))),LAMBDA(c,TEXTJOIN(" ",,c))))

  20. #20
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    I copied and pasted and got this error "The first argument of LET must be a valid name."

  21. #21
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    You have a European locale, so try this:

    =LET(z;B2:D2;d;DROP(REDUCE(0;z;LAMBDA(a;v;LET(t;TEXTSPLIT(v;;",");r;FILAS(t);HSTACK(a;VSTACK(r;ORDENARPOR(t;MATRIZALEAT(r)))))));;1);
    m;TAKE(d;1);BYROW(INDICE(d;RESIDUO(SECUENCIA(100;;0);m)+2;SECUENCIA(;COLUMNAS(d)));LAMBDA(c;UNIRCADENAS(" ";;c))))
    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.

  22. #22
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Hi. Now I get this error #NAME

  23. #23
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    TEXTSPLIT and some other functions are available in Mac: 16.65 (Build 220911) and later - you need to run an update on your Excel.
    Attached Files Attached Files
    Last edited by AliGW; 05-14-2023 at 02:40 AM. Reason: Workbook added.

  24. #24
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Hi - I have v 16.72 on Mac with 365 subscription.

  25. #25
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Quote Originally Posted by codeBeast View Post
    I copied and pasted and got this error "The first argument of LET must be a valid name."
    Who are you talking to?

  26. #26
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,906

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Then open the attachment in my previous post and see if that works. If not, then at least ONE of the functions is not available for you.

    And you need to update your profile, which says 16.37!

  27. #27
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Please explain EXACTLY how mine DOES NOT meet your requirement.

  28. #28
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Hi Glenn.
    Number of sentences to return - 1000
    Then I sort just to see what was generated with each name (people). It's perfect ie: I don't think a single sentence is duplicated.
    But when I use a value of - 100 only - I get a few repetitions of the person + verb. ie: I would prefer the verb phrase to be unique as long as possible.
    It's almost perfect and I will use it if I can't get that little edit for verb phrase uniqueness.

    My brother Bob is cutting the paper in the garden
    My brother Bob is cutting the paper in the mountain
    My brother Bob is going to the toilet in the house
    My brother Bob is going to the toilet in the sky
    My brother Bob is looking at the blackboard in the river
    My brother Bob is playing football in the class
    My brother Bob is singing a song in the house

  29. #29
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,055

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    No sentences are duplicated... ever. It generates all 12 x 16 x 7 = 1344 possible sentences and returns (randomly) n of them, where YOU define n.

    There are ONLY 12 name phrases (My brother Bob, etc). If you generate 100 sentences, then, randomly, you can expect to get each name appearing about 100/12, approximately 9 times.

    It is mathematically IMPOSSIBLE to generate more than 12 different starting phrases if there are only 12 possible starting phrases. Hence my request for you to explain clearly why my effort does not work.

    I still do not understand what you want to see!!

  30. #30
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    To Glen

    First sentences generated.

    My friend Freddy is dancing in the disco in the mountain
    My crazy cousin Franky is driving a car in the tree
    My dangerous daughter is playing football in the house
    My sunny son is eating a hamburger in the river
    My friend Freddy is driving a car in the river
    My crazy cousin Franky is playing football in the sky
    My dangerous daughter is singing a song in the garden
    My dangerous daughter is going to the toilet in the class
    My friend Freddy is drinking a coca-cola in the class
    My crazy cousin Franky is singing a song in the mountain
    My dad is going to the toilet in the tree

    Various people and verbs are repeated in the first 11 sentences for example.
    I would prefer to have a unique "people" value and verbs value every 12 or so sentences.
    So for example
    Instead of using My dangerous daughter 3 times in the first block of sentences, I need some of the other that haven't been used: The little boy, The little girl etc...

    Basically, because I will create activities using blocks of 10-12 sentences so i need them to be as unique as possible.
    Last edited by codeBeast; 05-14-2023 at 04:11 AM.

  31. #31
    Registered User
    Join Date
    08-18-2020
    Location
    Valencia
    MS-Off Ver
    Mac excel - Office 365 - v 16.72
    Posts
    61

    Re: Generate (concat) sentences from three columns - each column has multiple words in one

    Quick edit - I found the value to generate 1000 sentences - just in case you read my post before this edit.

    I have everything working with your formula. You were right and this works perfectly - generating a new person + unique verb phrase for quite a few rows.

    THaNK YOU so much.
    Last edited by codeBeast; 05-14-2023 at 04:13 AM.

+ 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. Replies: 5
    Last Post: 11-12-2019, 10:58 AM
  2. [SOLVED] Counting words in multiple sentences
    By sami770 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-28-2014, 08:34 AM
  3. [SOLVED] Column of single words as filter for columns with sentences
    By [email protected] in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 12
    Last Post: 01-23-2014, 12:11 PM
  4. Replies: 1
    Last Post: 01-20-2014, 04:03 PM
  5. Replies: 6
    Last Post: 01-17-2014, 10:41 AM
  6. Remove Stop Words from a column containing 16000 rows of sentences
    By Abhayrajify in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-30-2013, 07:14 PM
  7. [SOLVED] Search box in Excel to search key words in sentences in multiple worksheets
    By fernandoii676 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2012, 01:42 PM

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