+ Reply to Thread
Results 1 to 12 of 12

Find And Delete

  1. #1
    Registered User
    Join Date
    04-21-2006
    Posts
    17

    Find And Delete

    Hi

    Need a macro for deleting some unwanted strings.

    In each cell of Column A, every client name is trailed by different tags and then some unwanted space. For instance:

    Blazer/d...
    Rockwell-A.......
    Sigma Mills-DJ....
    Ikom-L..
    Sagmone Shoes/f............ (dots are spaces)

    I want all proper names to be cleaned of everything trailing, including extra spaces so that I get only client names:

    Blazer
    Rockwell
    Sigma Mills
    Ikom
    Sagmone Shoes

    That's pretty much it. Hope to have some good help

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Find And Delete

    Hi Maxal,

    If Blazer/d.. is in cell A1 then this formula will do what you need in B1

    =TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(A1,"/",REPT(" ",LEN(A1))),"-",REPT(" ",LEN(A1))),LEN(A1)))


    The above formula will stick a bunch of spaces for the "/" and "-" characters. Then it trims the left part of that to give what you want.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    04-21-2006
    Posts
    17

    Re: Find And Delete

    Hey MarvinP, thanx...but I am looking for a macro to do the job. I have to sort lots of data on daily basis.

    The content to be cleaned is in Column A and downwards, A1, A2, A3 etc.

  4. #4
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Find And Delete

    Looking for VBA code, Try this:-

    Please Login or Register  to view this content.
    Edit:- Correcting the compilers error.
    Last edited by Vikas_Gautam; 02-12-2015 at 02:02 PM.
    Regards,
    Vikas Gautam
    Excel-buzz.blogspot.com

    Excel is not a matter of Experience, its a matter of Application.

    Say Thanks, Click * Add Reputation

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Find And Delete

    Hi, Vikas,

    code will only replace the characters but not trim the rest of the cells from the character on as wanted by OP.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Find And Delete

    Yeah.. Holger I know.
    Will you suggested looping through then...?

  7. #7
    Registered User
    Join Date
    04-21-2006
    Posts
    17

    Re: Find And Delete

    Quote Originally Posted by Vikas_Gautam View Post
    Yeah.. Holger I know.
    Will you suggested looping through then...?
    Yes please, could anyone suggest a complete solution?

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Find And Delete

    Ok Maxal,

    Here is the VBA and example to do what you want. You can add to the list of last characters in the code. That is if you wanted ~ and : to also be "end of line" characters, you would change:
    LastChr = Split("/ -", " ") to
    LastChr = Split("/ - ~ :"," ")

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by MarvinP; 02-12-2015 at 11:43 AM.

  9. #9
    Registered User
    Join Date
    04-21-2006
    Posts
    17

    Re: Find And Delete

    Hey MarvinP, it works like a charm, except that there is a catch.

    I have some names that are divided by hyphens. Precisely speaking, mostly divided by "Al-" for instance, Al-Nikara, Al-Shiraza, Al-Yahso, etc. These "Al-" are always at the beginning of a word.

    Is there a way to add an exception to the code so that "Al-" is spared by the macro?

  10. #10
    Forum Expert Vikas_Gautam's Avatar
    Join Date
    06-04-2013
    Location
    Ludhiana,Punjab, India
    MS-Off Ver
    Excel 2013
    Posts
    1,850

    Re: Find And Delete

    Here is the workaround for Al-

    Please Login or Register  to view this content.

  11. #11
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Find And Delete

    Hi Maxal,

    To take care of your Al-Shiraza type names here is a revised code. Try this.

    This will check to see if the "-" happens in the first 3 letters. If it does then it will look for the "-" from the back of the string.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-21-2006
    Posts
    17

    Re: Find And Delete

    Thanx @MarvinP and @Vikas_Gautam. Both of you have been immensely helpful

+ 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. Replies: 4
    Last Post: 09-18-2012, 10:54 AM
  2. [SOLVED] Find a row with a specified value and then delete it!
    By Alezz in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 06-04-2012, 06:33 AM
  3. How to find duplicate entries, find which has the lowest value, and delete the rest?
    By John2810 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-05-2011, 06:39 AM
  4. Find and delete
    By Link in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-13-2009, 09:38 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