+ Reply to Thread
Results 1 to 16 of 16

Remove everything after a specific character in a cell...

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Remove everything after a specific character in a cell...

    Hi

    I have cells in column B and in each cell is a persons first name and last name.
    The first and last name is connected by a "_".

    Example "John_Doe"

    I want to go from Cell b2 down and remove the "_" and everything else to the right, leaving just the first name in the cell.

    How can I do this with VBA?

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Remove everything after a specific character in a cell...

    There is absolutely not need for macro or formula for something like this:

    1. Select the entire column with the name
    2. Use Ctrl+H to open a Find and Replace tool
    3. Type in _* in Find what: field
    4. Leave Replace with: blank and press Replace All.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Remove everything after a specific character in a cell...

    Maybe:

    Sub swade730y()
    Columns(2).Replace "_*", ""
    End Sub

  4. #4
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Remove everything after a specific character in a cell...

    Tha would remove the "_". I want to keep what is after the "_" or What is before the "_" (First OR Last Name)

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Remove everything after a specific character in a cell...

    Quote Originally Posted by swade730 View Post
    Tha would remove the "_". I want to keep what is after the "_" or What is before the "_" (First OR Last Name)
    Now you contradict your original requirements: "I want to go from Cell b2 down and remove the "_" and everything else to the right, leaving just the first name in the cell."

  6. #6
    Registered User
    Join Date
    05-28-2015
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    5

    Re: Remove everything after a specific character in a cell...

    I got something like a few data
    12345/1
    12345/1 , 56778/1
    i only want remove the things after "/"
    how do i do that keeping the comma and the other digits

  7. #7
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Remove everything after a specific character in a cell...

    Alkey give you the solution for that in #2

    There is absolutely not need for macro or formula for something like this:

    1. Select the entire column with the name
    2. Use Ctrl+H to open a Find and Replace tool
    3. Type in /* in Find what: field
    4. Leave Replace with: / and press Replace All.
    Last edited by oeldere; 06-02-2015 at 02:24 AM. Reason: Replace with /
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  8. #8
    Registered User
    Join Date
    05-28-2015
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    5

    Re: Remove everything after a specific character in a cell...

    as in i have data such as 1234/1, 0340304/2 and the results should be something like 1234, 0340304

  9. #9
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Remove everything after a specific character in a cell...

    You get better help if you add a small excel file, without confidential information.

    Please add manualy the expected results in the file.

  10. #10
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Remove everything after a specific character in a cell...

    Hi icecreame,

    You can use this formula - just change the cell reference to suit:

    =LEFT(A2,SEARCH("/",A2)-1)

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  11. #11
    Registered User
    Join Date
    05-28-2015
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    5

    Re: Remove everything after a specific character in a cell...

    Quote Originally Posted by Trebor76 View Post
    Hi icecreame,

    You can use this formula - just change the cell reference to suit:

    =LEFT(A2,SEARCH("/",A2)-1)

    Regards,

    Robert
    Hi Robert/Oeldere,

    Thanks for your responsive reply but i cant get the right data i want, the formula keeps removing the data that i even wanted so I was having 1234/1 , 43240/23 after using the formula im left with 1234 only but i want both 1234 , 43240 any idea how to do it?

    Regards
    Icereame

  12. #12
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Remove everything after a specific character in a cell...

    Not sure as it works for me

    Check that the calculation method of the workbook is set to automatic.

  13. #13
    Registered User
    Join Date
    05-28-2015
    Location
    Singapore
    MS-Off Ver
    2010
    Posts
    5

    Re: Remove everything after a specific character in a cell...

    yeah it is automatic not sure why man

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: Remove everything after a specific character in a cell...

    You get better help if you add a small excel file, without confidential information.
    Please add manually the expected results in the file.
    Seeing the workbook should provide the answer

  15. #15
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: Remove everything after a specific character in a cell...

    Quote Originally Posted by Trebor76 View Post
    Seeing the workbook should provide the answer
    I will provide this

  16. #16
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Remove everything after a specific character in a cell...

    @ icecreame, Maybe:

    Sub icecreame()
    Dim rcell As Range
    For Each rcell In Range("A2:A" & Range("A" & Rows.Count).End(3).row)
        rcell.Value = Val(rcell)
    Next rcell
    End Sub

+ 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. Remove Specific Character from Cell
    By maniacalmonkey in forum Excel General
    Replies: 3
    Last Post: 09-11-2014, 07:58 PM
  2. [SOLVED] How do I remove all text in a cell after a specific character?
    By Erik Millerd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  3. [SOLVED] How do I remove all text in a cell after a specific character?
    By Erik Millerd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. How do I remove all text in a cell after a specific character?
    By Erik Millerd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  5. [SOLVED] How do I remove all text in a cell after a specific character?
    By Erik Millerd in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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