+ Reply to Thread
Results 1 to 23 of 23

Macro for removing 2 letters words

  1. #1
    Registered User
    Join Date
    03-24-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    3

    Macro for removing 2 letters words

    Hi guys!:

    I need really need your help for this.
    I was looking for a macro that could automatically detect and remove 2 letter words (for example: or, if, hg, wa, rt, op...) in a selected range (it will be almost always in column A)

    Also, i wanted to put this macro some words that it should not remove (because i work with some products with 2 letter brand such as LG, CH, DG...) I was thinking that i could add a list to this macro.
    For example

    in and out we went to the top of the hill---------------------> and out went the top hill
    of one to many we see an answer------------------------------>one many see answer
    df is gh is fe on off----------------------->is is on off ("is" is not removed because i need this word, as well as a list that i have of 2 letters word)


    Thank you in advance guys!

    Waiting for your replies.

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2012
    Location
    Barrington, IL
    MS-Off Ver
    Excel 2007/2010
    Posts
    1,211

    Re: Macro for removing 2 letters words

    If this task isn't something you'll need to do regularly, I'm thinking you could just use find and replace. Not as interesting as a macro, but it would work fine and be relatively fast since there aren't too too many two letter words likely to exist. Select all the data and use Find and replace on anything that is [Space] letter letter [Space] with a single [Space], and repeat for each word.

    so find " in " and replace with " "

    The macro would be interesting and I'd like to see one, but if this is an immediate need, a manual find/replace that would work for you as well and would only take a few minutes. Unless there are a lot of combinations that aren't words like xo and qm or something, in which case...macro
    You should hit F5, because chances are I've edited this post at least 5 times.
    Example of Array Formulas
    Quote Originally Posted by Jacc View Post
    Sorry, your description makes no sense. I just made some formula that looks interesting cause I had nothing else to do.
    Click the * below on any post that helped you.

  3. #3
    Registered User
    Join Date
    03-24-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    3

    Re: Macro for removing 2 letters words

    Hi:

    Actually there are a lot of combinations of 2 letters, it's almost impossible to do it right manually. That is why i'm looking for a macro that can help me

  4. #4
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Macro for removing 2 letters words

    Try this:
    Please Login or Register  to view this content.
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  5. #5
    Registered User
    Join Date
    03-24-2017
    Location
    Spain
    MS-Off Ver
    2016
    Posts
    3

    Re: Macro for removing 2 letters words

    Hi:

    Thank you for your answer, but it is not working for me

    Let me attacth you a sample of what i want
    Attached Files Attached Files

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    Hi haoxu

    This code works to remove the 2 letter words, however, not sure where to add the code for the exceptions. Perhaps someone else can assisst in editing as required.
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro for removing 2 letters words

    This uses Regular Expressions to filter all two-letter words. The RegEx pattern could be adjusted to exclude a list of two-letter words, but I don't know how to add the word exclusions. Perhaps someone could suggest a pattern.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Macro for removing 2 letters words

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,525

    Re: Macro for removing 2 letters words

    sintek's code with the check he/she requested.

    Please Login or Register  to view this content.

  10. #10
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    @ jolivanes

    Well look at that....Fantastic...Thanks for the lesson

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Macro for removing 2 letters words

    Add to the pattern like mk| separate it by pipe, if you have more.
    Please Login or Register  to view this content.

  12. #12
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318

    Re: Macro for removing 2 letters words

    Quote Originally Posted by Logit View Post
    Please Login or Register  to view this content.
    This VBA code is identical with VBA code from here http://www.vbaexpress.com/forum/showthread.php?58988-Macro-for-removing-2-letters-word.
    Who actually wrote the VBA code ???

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    Hey there Indi_Ra

    It is not actually about who wrote the code...The forum is a platform where one learns from....As long as the code works....That is important.

  14. #14
    Banned User!
    Join Date
    10-29-2012
    Location
    Europe
    MS-Off Ver
    2013, 2016
    Posts
    318
    Quote Originally Posted by sintek View Post
    Hey there Indi_Ra

    It is not actually about who wrote the code...The forum is a platform where one learns from....As long as the code works....That is important.
    Probably we have different concepts....
    If we took VBA code from someone, it is normal and common sense, to say who wrote it and do not take credit...
    As I said it is primarily a matter of common sense...

    If someone steals your heat from your head, could have an excuse, raining outside....
    Last edited by Indi_Ra; 03-27-2017 at 06:28 AM.

  15. #15
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro for removing 2 letters words

    @sintek - we all learn from each other and we all borrow bits of code and integrate it into our code and modify it etc - then it becomes our code - and that is fine.

    If we take someone else's code and do not change it (or change it very little) then it is still their code - they don't "own" it, but it is still their work.
    If you then post it elsewhere, it is "etiquette" to mention the source (if you can remember) and it is very nice for the code writer to be given credit.
    It costs you nothing and to the rest of us it makes you a "better person" for being honest about who wrote the code.
    The originator gets the credit, the person with the problem gets a solution, you get an acknowledgement for helping that person etc - WIN, WIN , WIN
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  16. #16
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: Macro for removing 2 letters words

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    http://www.vbaexpress.com/forum/show...-letters-word.

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    @ kev

    I understand..Thank you

  18. #18
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    Quote Originally Posted by Indi_Ra View Post
    Probably we have different concepts....
    If we took VBA code from someone, it is normal and common sense, to say who wrote it and do not take credit...
    As I said it is primarily a matter of common sense...

    If someone steals your heat from your head, could have an excuse, raining outside....
    Agreed, thanks

  19. #19
    Registered User
    Join Date
    02-09-2016
    Location
    Perth
    MS-Off Ver
    2010
    Posts
    8

    Re: Macro for removing 2 letters words

    Hi Kev
    I agree with that sentiment.
    Who actually wrote the VBA code ???
    I did, (except for the comments)
    mdmackillop

  20. #20
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Macro for removing 2 letters words

    I agree that anything posted on a public forum becomes - well public domain.

    Having said that though, common courtesy would be to post acknowledgement on where the code/formula/whatever came from
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  21. #21
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Macro for removing 2 letters words

    Quote Originally Posted by kev_ View Post
    @sintek - we all learn from each other and we all borrow bits of code and integrate it into our code and modify it etc - then it becomes our code - and that is fine.

    If we take someone else's code and do not change it (or change it very little) then it is still their code - they don't "own" it, but it is still their work.
    If you then post it elsewhere, it is "etiquette" to mention the source (if you can remember) and it is very nice for the code writer to be given credit.
    It costs you nothing and to the rest of us it makes you a "better person" for being honest about who wrote the code.
    The originator gets the credit, the person with the problem gets a solution, you get an acknowledgement for helping that person etc - WIN, WIN , WIN
    Well said. We do not have an explicit rule requiring it here, but professional courtesy requires that you credit the source of code if you did not write it yourself.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  22. #22
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Macro for removing 2 letters words

    Quote Originally Posted by sintek View Post
    Hey there Indi_Ra

    It is not actually about who wrote the code...The forum is a platform where one learns from....As long as the code works....That is important.
    Hey guys. I have only been able to get to this point in my "Beginner" level of VBA by searching the web and making use of this Amazing Forum.
    I have always taken code found on the web and adjusted to suite my requirements, sometimes just a small tweak and sometimes large tweaking.
    I have never assumed to be the code writer and have always thanked the Contributor if assistance came from this site. I learned something new today and promise in future will always give credit to the original author...

  23. #23
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro for removing 2 letters words

    Nice one @sintek

+ 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. COMBINE LETTERS into WORDS
    By JPSQ in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-24-2022, 07:52 PM
  2. Count letters/words
    By PhilS5 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-03-2014, 05:06 PM
  3. Replies: 13
    Last Post: 07-30-2014, 12:03 PM
  4. [SOLVED] Removing letters from text & letters combination
    By benoj2005 in forum Excel General
    Replies: 5
    Last Post: 02-26-2014, 11:20 AM
  5. Removing words under 4 letters
    By jeremyh09 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-30-2013, 12:23 AM
  6. [SOLVED] I need a macro that allows only lists of numbers and not letters or words
    By denisirio in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-24-2012, 12:01 PM
  7. [SOLVED] Removing all rows that contain letters
    By fred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2005, 12:06 PM

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