+ Reply to Thread
Results 1 to 9 of 9

extract Maximum Length text from a Text String

  1. #1
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    extract Maximum Length text from a Text String

    Hi Masters.

    "In this text string which text has maximum length"

    Answer is maximum

    I have built a formula which works good but it is too biggi...

    B2=INDEX(INDEX(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),((ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1)))-1)*LEN(A1)+1,LEN(A1))),),MATCH(MAX(INDEX(LEN(INDEX(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),((ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1)))-1)*LEN(A1)+1,LEN(A1))),)),)),INDEX(LEN(INDEX(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",LEN(A1))),((ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1," ",""))+1)))-1)*LEN(A1)+1,LEN(A1))),)),),0))

    Any alternative will be great and it should also non array
    If I helped, Don't forget to add reputation (click on the little star ★ at bottom of this post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: extract Maximum Length text from a Text String

    Why not use User Defined Function?
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: extract Maximum Length text from a Text String

    I used it

    I would create a name Manger Name would be Array and refer to field paste below one.

    =TRIM(MID(SUBSTITUTE(Sheet1!$A1," ",REPT(" ",LEN(Sheet1!$A1))),((ROW(INDIRECT("1:"&LEN(Sheet1!$A1)-LEN(SUBSTITUTE(Sheet1!$A1," ",""))+1)))-1)*LEN(Sheet1!$A1)+1,LEN(Sheet1!$A1)))

    then

    B2=INDEX(ArraY,MATCH(MAX(INDEX(LEN(ArraY),)),INDEX(LEN(ArraY),),0))

    But need something more shorter

  4. #4
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract Maximum Length text from a Text String

    How do you want to handle if more than one word in the input string are the same maximum length?

    e.g. "This is my example of a working formula" - the words example, working and formula are all 7 characters long. What is your required output?
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  5. #5
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: extract Maximum Length text from a Text String

    Good questing Olly I did not thing about this lolx. This thread was raised by my colleague, I will ask him about this condition

  6. #6
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: extract Maximum Length text from a Text String

    Okay - here's a UDF which can handle extracting the first, last, or ALL longest words from an input string:

    Please Login or Register  to view this content.
    Use like this:
    A B C D E
    1 Input First Last Default Join Custom Join
    2 In this text string which text has maximum length maximum maximum maximum maximum
    3 This is my example of a working formula example formula example, working, formula example | working | formula
    4 =LongestWord(A3,1) =LongestWord(A3,2) =LongestWord(A3,0) =LongestWord(A3,0,"" | "")

  7. #7
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: extract Maximum Length text from a Text String

    VBA is just amazing thank you olly for the code but I am hoping for formula solutions What alternative can be?

  8. #8
    Forum Expert tim201110's Avatar
    Join Date
    10-23-2011
    Location
    Russia
    MS-Off Ver
    2016, 2019
    Posts
    2,357

    Re: extract Maximum Length text from a Text String

    helper columns/rows help a lot
    Attached Files Attached Files

  9. #9
    Forum Expert shukla.ankur281190's Avatar
    Join Date
    05-17-2014
    Location
    Lucknow, India
    MS-Off Ver
    Office 365
    Posts
    3,937

    Re: extract Maximum Length text from a Text String

    This looks spooky TIM, but thanks for your time.

+ 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] Extract text from end of string with varying length
    By reedersketer in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-08-2015, 05:16 PM
  2. Extract text between two characters in a string - varing text length
    By luv2birdie in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-04-2014, 06:10 PM
  3. Replies: 4
    Last Post: 08-13-2014, 11:03 PM
  4. Extract Variable Length Text String
    By sshot1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-12-2012, 06:21 PM
  5. Replies: 6
    Last Post: 03-08-2012, 10:35 AM
  6. [SOLVED] EXTRACT TEXT FROM TEXT STRING:The names are of variable length
    By carricka in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-08-2005, 06:05 AM
  7. Replies: 1
    Last Post: 04-17-2005, 08:10 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