+ Reply to Thread
Results 1 to 15 of 15

macro for find and replace from list

  1. #1
    Registered User
    Join Date
    03-23-2012
    Location
    New Albany, Indiana
    MS-Off Ver
    Excel 2007
    Posts
    5

    macro for find and replace from list

    So i am trying to obtain code that will allow me to find a value in Column A and replace it with the value in column H using the list in columns G:H. In other words I would like it to loop through the spreadsheet and replace a particular word in Column A with the word in column H every time it finds it in the spreadsheet.sample find and replace worksheet.xlsx

  2. #2
    Valued Forum Contributor
    Join Date
    03-14-2012
    Location
    Arizona USA
    MS-Off Ver
    Excel 2000/2007
    Posts
    408

    Re: macro for find and replace from list

    Your sample is a bit confusing.

    I assume;
    Column A has the original list to be updated.
    Column G has all the BEFORE names. The names to be changed(Before the change).
    Column H has all the AFTER names. The new names(After the change).

    Is this correct?

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    Hi jgelbach
    Welcome to the Forum!!
    It appears to me Column A and Column G are the same in all respects. If so, what am I missing...simply copy Column H to Column A.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake,

    Hello John,

    Exactly what I thought as well, but what if a row in g just happend to be different?, then it should not copy the Cell H of that row.

    I am looking into comparing values in Column A with that in Column G, and only if it is in fact the same, then Copy Column H to Column A. But I am having a bit of trouble getting some code to work along this assumption.

    Care to help?

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    @Winon
    Probably something like this
    Please Login or Register  to view this content.
    Sorry that would be
    Please Login or Register  to view this content.
    Last edited by jaslake; 03-23-2012 at 03:19 PM.

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jazlake,

    Very well done John. The WorkBook now looks like this and your code works like magic!
    Attached Files Attached Files

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake,

    Hello John,

    I found that if there are empty rows between Data entered your Code stops at the first empty row.

    So I came up with this, to take care of empty rows as well:

    Please Login or Register  to view this content.
    Enjoy your weekend!
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    @Winon
    I don't know what scenario you've developed to cause this
    your Code stops at the first empty row
    Whatever the scenario, it needs to be dealt with. This line of code does not deal with it, it prematurely ends the sub.
    Please Login or Register  to view this content.

  9. #9
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake,

    Hello John,

    Whatever the scenario, it needs to be dealt with. This line of code does not deal with it, it prematurely ends the sub.
    Please Login or Register  to view this content.

    The
    Else:
    Does NOT end anything prematurely, it simply implicates that if certain conditions are not met, THEN exit or whatever!


    Am am not saying that the original Code you gave is wrong, in fact it might hold true within certain requirements, but I merely suggested an alternative Code if there was an empty row within the range your code was looking at, whilst the requirement was to cover the whole range, empty rows despite.

    With the Code you offered as, "Probably something like", I inserted a blank row or more, and found that "Probably something like" stopped at the first empty row, and did not cover the whole range, empty row/s despite.

    So, in short, just to clarify and not fight, I was only trying to explain to you the different ways of looking at this specific situation.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    @Winon
    Not "fighting"...simply made an observation. Show me the scenario that causes this
    I inserted a blank row or more, and found that "Probably something like" stopped at the first empty row
    In my copy of the file I inserted three blank rows at Rows 2, 3 and 4...the code passed right by them and went on to Row 5. So, I don't know how you modified the file such that it gives you cause for concern. Show me so I understand.

  11. #11
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake,

    Hello John,

    Thank you for your response and not "Fighting"

    Here you go, check out the WorkBook attached with your "Probably something like" Code and empty rows.
    Attached Files Attached Files

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    @ Winon
    Again, not arguing (or fighting) but my observation stands...the procedure does end prematurely and should be dealt with. Here's the code I'd suggest to deal with it.
    Please Login or Register  to view this content.
    I should point out, this code is not appropriate when one has blank rows
    Please Login or Register  to view this content.
    Last edited by jaslake; 03-25-2012 at 02:33 PM.

  13. #13
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake,

    Hello John,


    Tried and tested the NEW CODE:

    Please Login or Register  to view this content.
    Works like a charm however, I cannot find any posts in this thread, offering this solution prior to my alert!

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: macro for find and replace from list

    Quote Originally Posted by Winon View Post
    @ jaslake,

    I cannot find any posts in this thread, offering this solution prior to my alert!
    Neither do I. So, put this in you're toolbox...if you anticipate empty cells in a column and you're looking for the last row in that column, don't use this approach
    Please Login or Register  to view this content.
    as .End(xlDown) ends the blank cell.

  15. #15
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: macro for find and replace from list

    @ jaslake

    LOL, thanks John,

    I got to realise that, and all I can say is, Ditto!

    Thank you so much for your input, looking forward to "fighting" with you again!!!

+ 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