+ Reply to Thread
Results 1 to 7 of 7

Find all/Select All/Replace all

  1. #1
    Forum Contributor
    Join Date
    03-02-2010
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    109

    Find all/Select All/Replace all

    Good afternoon.

    I have spent most of the day researching and trying a variety of things, but have yet to find something that works. I'm hoping someone here can once again teach me how to do this.

    I have a spreadsheet that has been exported out of document direct. It lists each of the locations over two regions and the formatting is less than ideal. I've figured out how to extract the data I need, but I'm trying to automate the process. From start to finish, I have to sets of words that I use "Find all" for, copy all of them at once, and paste them to a new sheet. I use text to columns (which I did figure out the code for) to break down the information, and get rid of everything I don't need

    Next, I find the second search word, copy all instances over to the new sheet, and then do a find and replace all for the words YTD Controlled W/O. I replace it so that all of the spaces are removed.

    Then I again do the text to columns, delete all of the information I don't need, and it's done.

    What I'm having trouble figuring out is how to do the "Find all" function and by extension the "Replace all" function, through VBA. Is there a way to do this?

    I greatly appreciate any and all help, and hope everyone has a great weekend.
    Last edited by just_some_guy; 05-16-2011 at 11:53 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,359

    Re: Find all/Select All/Replace all

    Record a macro while you do a replace all on your spreadsheet. That will give you the basis for your code. You'll then need to tweak it to generalise it.

    I suggest that you post a sample workbook when you have some code you need help with. It can be difficult inventing sample data, workbook/worksheet structure and then developing code ... and it's unlikely to match what you have and need.

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Find all/Select All/Replace all

    Hi,

    You can play around with this script below,Post back additional Questions and as TM said post a dummy workbook that always helps.

    Please Login or Register  to view this content.
    .
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  4. #4
    Forum Contributor
    Join Date
    03-02-2010
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Find all/Select All/Replace all

    TM,

    Thanks very much for the tip. When the recorder didn't put in any code for the "Find" function, I for some reason just assumed it would not do it for the "Replace" function either. Stupid assumption.

    RealNiceGuy,

    Thanks for the code. After a bit of tweeking, it does exactly what I need it to. I'm still running into trouble getting the "Find All" function to work in VBA. Any tips for that, from either of you?

    Thanks again for your help. It is very much appreciated.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,359

    Re: Find all/Select All/Replace all

    Some basic, untweaked code for Replace All and for Find (apart from making it more readable):

    Please Login or Register  to view this content.

    Please Login or Register  to view this content.

    Regards

  6. #6
    Forum Contributor
    Join Date
    03-02-2010
    Location
    Denver, CO
    MS-Off Ver
    Excel 2010
    Posts
    109

    Re: Find all/Select All/Replace all

    TM, you're just about my favorite person in the world right now for the "Find" macro. I had to tweek it just a bit to fit my needs, but it is absolutely perfect.

    Thanks a lot for all your help!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,359

    Re: Find all/Select All/Replace all

    You're welcome. Doubly solved :-)

+ 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