+ Reply to Thread
Results 1 to 6 of 6

Trim formula

Hybrid View

stemcell1 Trim formula 10-23-2008, 10:53 AM
Ron Coderre Parsing text 10-23-2008, 11:08 AM
stemcell1 Thanks Ron! That was very... 10-23-2008, 11:17 AM
martindwilson well for first part ... 10-23-2008, 12:23 PM
Ron Coderre Parsing text with a delimiter 10-23-2008, 12:39 PM
stemcell1 That is probably the longest... 10-23-2008, 12:39 PM
  1. #1
    Registered User
    Join Date
    05-23-2007
    Location
    San Diego, CA
    Posts
    59

    Trim formula

    I have been using the following formula's to trim some information that's separated by a colon, such as Pioneer Clinic:Dave McAfee...so that I have a column with Pioneer Clinic and a column with Dave McAfee:

    =LEFT(G5,FIND(":",G5)-1)
    =TRIM(RIGHT(G5,LEN(G5)-FIND(":",G5)))

    However, now some of my data is separated by two colons!
    AVM:Pioneer Clinic:Dave McAfee

    Can anyone show me the formula for separating this so I still have two columns of Pioneer Clinic and Dave McAfee?

    Thanks!
    Last edited by VBA Noob; 10-23-2008 at 12:46 PM.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Parsing text

    With
    G5 containing a text phrase containing 1 or 2 colons.

    These formula parse that phrase into two sections.
    The part AFTER the last colon
    I5: =MID(G5,FIND(CHAR(7),SUBSTITUTE(G5,":",CHAR(7),
    LEN(G5)-LEN(SUBSTITUTE(G5,":",""))))+1,255)
    The part up to the last colon
    H5: =SUBSTITUTE(G5,":"&I5,"")
    Note: CHAR(7) is the ASCII code for sounding a PC Bell

    Is that something you can work with?
    Last edited by Ron Coderre; 10-23-2008 at 11:11 AM. Reason: add a comment
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    05-23-2007
    Location
    San Diego, CA
    Posts
    59
    Thanks Ron! That was very helpful!!!

    On the second formula, can you tell me how to get to the middle portion of information:

    ie AVM:Pioneer Clinic:Dave McAfee

    The second formula you posted gave me AVM:Pioneer Clinic, but I need to show just Pioneer Clinic and get rid of the AVM. I've played with the MID and TRIM and LEFT but haven't been able to come up with a formula that works.

    Thanks so much! It's so nice when people respond with actual suggestions instead of just telling me to go to the help files...obviously I already tried that and couldn't figure it out!!

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    well
    for first part
    =IF(LEN(A1)-LEN(SUBSTITUTE(A1,":",""))>1,MID(SUBSTITUTE(A1,":","/",1),FIND("/",SUBSTITUTE(A1,":","/",1))+1,FIND(":",SUBSTITUTE(A1,":","/",1))-FIND("/",SUBSTITUTE(A1,":","/",1))-1),LEFT(A1,FIND(":",A1)-1))
    for second part

    =IF(LEN(A1)-LEN(SUBSTITUTE(A1,":",""))>1,TRIM(RIGHT(SUBSTITUTE(A1,":","/",1),LEN(SUBSTITUTE(A1,":","/",1))-FIND(":",SUBSTITUTE(A1,":","/",1)))),TRIM(RIGHT(A1,LEN(A1)-FIND(":",A1))))
    where a1 contains your original text

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Parsing text with a delimiter

    I didn't realize that you wanted all 3 sections if there are 2 colons

    With
    G5: (the text to parse....eg AVM:Pioneer Clinic:Dave McAfee)

    This formula returns the part after the LAST colon
    J5: =MID(G5,FIND(CHAR(8),SUBSTITUTE(G5,":",CHAR(8),
    LEN(G5)-LEN(SUBSTITUTE(G5,":",""))))+1,255)
    This formula returns the AVM part....only if there are 2 colons
    otherwise it is blank ("")
    H5: =IF(LEN(G5)-LEN(SUBSTITUTE(G5,":",""))=2,LEFT(G5,FIND(":",G5)-1),"")
    This formula returns the section BEFORE the last colon
    (EDITED to correct a formula error)
    I5: =MID(SUBSTITUTE(G5,":"&J5,""),LEN(H5)+1+(LEN(H5)>0),255)
    In the above example, these values are returned:
    AVM
    Pioneer Clinic
    Dave McAfee

    Does that help?
    Last edited by Ron Coderre; 10-23-2008 at 12:47 PM. Reason: edit the formula for cell I5

  6. #6
    Registered User
    Join Date
    05-23-2007
    Location
    San Diego, CA
    Posts
    59
    That is probably the longest formula I have ever seen, but it worked!!! Thank you Martind!!!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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