+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    03-18-2010
    Location
    Illinois, America
    MS-Off Ver
    Excel 2007
    Posts
    2

    Deleting everything after certain character

    Is there any way to delete everything after a certain character or word?
    EXAMPLE: "example– 3:47"
    Is there any way to delete everything after the "–" in every cell or a specified group of cells?
    Thanks in advance
    -Tom

  2. #2
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,477

    Re: Deleting everything after certain character

    find -* replace with nothing
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Deleting everything after certain character

    Hello Tom,

    welcome to the forum. You can use the LEFT and FIND functions in a combination in another cell. For your example above:

    =LEFT(A1,FIND(CHAR(150),A1))

    The dash in your example is the character 0150, for a simple dash as found on the keyboard, use

    =LEFT(A1,FIND("-",A1))

    Copy the formula down the column of your data. You can copy the result and use Paste Special - Values to copy only the values elsewhere.
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  4. #4
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,242

    Re: Deleting everything after certain character

    You can have a formula in another cell that does that truncation

    =LEFT(A1,FIND("-",A1))

    If you want to do it in place, then you need some VBA.

    Code:
    ' Find all occurrences of char in worksheet and truncate any characters following it
    Public Sub TruncAfter(char As String)
       Dim c As Range
       Dim pos As Long
       For Each c In UsedRange
          pos = InStr(c.Value, char)
          If pos > 0 Then
             c.Value = Mid(c.Value, 1, pos)
          End If
       Next c
    End Sub
    This code is written to go in the sheet with the data. If you want a more general solution use this, which can go in a Module:

    Code:
    ' Find all occurrences of char in worksheet and truncate any characters following it
    Public Sub TruncAfter(ws as Worksheet, char As String)
       Dim c As Range
       Dim pos As Long
       For Each c In ws.UsedRange
          pos = InStr(c.Value, char)
          If pos > 0 Then
             c.Value = Mid(c.Value, 1, pos)
          End If
       Next c
    End Sub
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  5. #5
    Forum Guru 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Vienna, VA, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    2,242

    Re: Deleting everything after certain character

    Quote Originally Posted by martindwilson View Post
    find -* replace with nothing
    Ooh, that's much better than writing all that code I have to admit I didn't know Excel find & replace supported wildcards.

    However, to delete everything after the "-" you would replace -* with -.
    Last edited by 6StringJazzer; 03-18-2010 at 09:23 PM.
    Making the world a better place one fret at a time
    ||||||

    If someone helped you, please click on the star icon at the bottom of their post

    If your problem is solved, please update the first post:
    EDIT, Go Advanced button, set Prefix to SOLVED

    [code]
    ' Enclose code in tags like this
    [/code]

    Don't attach a screenshot
    --just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  6. #6
    Forum Guru martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    10,477

    Re: Deleting everything after certain character

    edit ah i was just going to say that lol but if it is char 150 then find
    hold down alt and key 0150 on the numeric keypad then put * will do it
    Last edited by martindwilson; 03-18-2010 at 09:25 PM.
    Mojito connoisseur and a dabbler in Cisco
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  7. #7
    Registered User
    Join Date
    03-18-2010
    Location
    Illinois, America
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Deleting everything after certain character

    THANK YOU SO MUCH!
    the one that is easiest that i used was the tip on replacing "–*" with nothing. This will save me so much time. Thank you again
    -Tom

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.2.0