+ Reply to Thread
Results 1 to 7 of 7

Extract each substring from current cell

Hybrid View

clickcoder Extract each substring from... 02-15-2010, 10:53 AM
6StringJazzer Re: Extract each sub string... 02-15-2010, 12:48 PM
clickcoder Re: Extract each sub string... 02-16-2010, 03:22 AM
mdbct Re: Extract each sub string... 02-15-2010, 01:07 PM
DonkeyOte Re: Extract each sub string... 02-15-2010, 03:59 PM
clickcoder Re: Extract each substring... 02-16-2010, 04:51 AM
6StringJazzer Re: Extract each substring... 02-16-2010, 10:48 AM
  1. #1
    Registered User
    Join Date
    02-15-2010
    Location
    Turkey
    MS-Off Ver
    Excel 2007
    Posts
    3

    Extract each substring from current cell

    Hi friends,

    A1 cell data is : Microsoft (MS) Google (G) Yahoo (Yho)

    I want to extract each words who start with ( and end with ).

    B1 will be (MS)
    C1 will be (G)
    D1 will be (Yho)

    How can I do that?

    Thank you

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: Extract each sub string from current cell

    Here are two solutions. The first requires "helper" cells. It's more efficient but if you don't care for that you can construct "megaformulas" as shown in the second solution.
    Attached Files Attached Files
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    02-15-2010
    Location
    Turkey
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract each sub string from current cell

    Quote Originally Posted by 6StringJazzer View Post
    Here are two solutions. The first requires "helper" cells. It's more efficient but if you don't care for that you can construct "megaformulas" as shown in the second solution.
    Dear 6StringJazzer,

    Complex one is good for me But when I look your example it couldn't found 3rd (Yho)

    Thanks for all friends for their suggestions

  4. #4
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Extract each sub string from current cell

    Try this one:
    ="(" & MID(SUBSTITUTE($A1,"(","|",COLUMN()-1),FIND("|",SUBSTITUTE($A1,"(","|",COLUMN()-1))+1,FIND(")",SUBSTITUTE($A1,"(","|",COLUMN()-1),FIND("|",SUBSTITUTE($A1,"(","|",COLUMN()-1)))-FIND("|",SUBSTITUTE($A1,"(","|",COLUMN()-1)))

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Extract each sub string from current cell

    Another single cell alternative perhaps:

    B1:
    ="("&TRIM(MID(SUBSTITUTE(SUBSTITUTE($A1,"(",REPT(" ",255),COLUMNS($B1:B1)),")",REPT(" ",255),COLUMNS($B1:B1)),255,255))&")"
    copied across to D1

  6. #6
    Registered User
    Join Date
    02-15-2010
    Location
    Turkey
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract each substring from current cell

    For last word I used
    =RIGHT(A2,LEN(A2)-FIND("^^",SUBSTITUTE(A2,"(","^^",LEN(A2)-LEN(SUBSTITUTE(A2,"(",""))))+1)

    But still don't like this solution because if I have more than 4 parantheses it will crash

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: Extract each substring from current cell

    I had an error, which is corrected in the attached but the formula becomes very unwieldy compared to the ones above.

    I have also added a UDF here if you care to use one, also in the attached.

    ' Extract the nth occurrence of text delimited by ldelim and rdelim, including the
    ' delimiters
    Public Function DelimitedText( _
                      c As Range, _
                      ldelim As String, _
                      rdelim As String, _
                      Optional n As Long = 1) _
                    As String
    
       Dim s As Variant
       Dim stemp As String
       Dim result As Variant
       
       result = InStr(c.Value, ldelim)
       If result = 0 Then
          DelimitedText = "#LDELIM!" ' left delimited not found
       Else
       
          s = Split(c.Value, ldelim)
          stemp = ldelim & s(n)
          result = InStr(stemp, rdelim)
          If result = 0 Then
             DelimitedText = "#RDELIM!" ' right delimiter not found
          Else
             DelimitedText = Mid(stemp, 1, InStr(stemp, rdelim))
          End If
       End If
    
    End Function
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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