+ Reply to Thread
Results 1 to 6 of 6

Find and Replace one cell at a time

  1. #1
    Registered User
    Join Date
    10-14-2009
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    4

    Find and Replace one cell at a time

    I am writing a VB.net addin for excel.

    I have a large workbook with many different worksheets. The workbook is composed of catalog type sheets and relational sheets. I want to change a value on the catalog sheet and for the change to be persisted throughout the rest of the workbook. However, I want to consider each cell before changing the value in order to not replace certain types of values such as cells with guids in them. For example:

    I change "T0001" to "T9999" in my catalog sheet. In my relational sheet I have one cell value "T0001" and another cell with a value of "{b2dc9ad6-652d-431a-bdd8-2918172T0001}". I want to replace the first instance of T0001 but do not want to replace the T0001 that's found in the guid of the second cell's value. Is there a way to do this? Here is my code:
    Please Login or Register  to view this content.
    Last edited by jstites; 10-14-2009 at 05:29 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find and Replace one cell at a time

    Hello jstites,

    Welcome to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    Use the Bulletin Board Code Tags
    [code]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/code] at the end of the last line.


    To learn more about BB codes used in this forum, just click on the link below...

    Bulletin Board Codes Tags
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-14-2009
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and Replace one cell at a time

    Thanks Leith. I will do that from now on. Any insight into my problem?

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Find and Replace one cell at a time

    You'll see that macro recorder generates code something like this for Find
    Please Login or Register  to view this content.
    You need to make sure the LookAt parameter is set to xlWhole.

  5. #5
    Registered User
    Join Date
    10-14-2009
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and Replace one cell at a time

    I left out another cell value that I would want to change which makes me not able to use what you have.

    T0001 should change to T9999
    T0001; T0002 should change to T9999; T0002
    "{b2dc9ad6-652d-431a-bdd8-2918172T0001" should not change.

    I have a way to determine whether or not I want to change the cell. All I need to know is how to do a find and replace by cell rather than by the sheet. With my code it changes all cells in that sheet to the new value based off the first cell's change result. Even if the others don't meet the change criteria. So I would like to evaluate each cell's value prior to changing.

  6. #6
    Registered User
    Join Date
    10-14-2009
    Location
    Fort Worth, TX
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Find and Replace one cell at a time

    I found something that will work. Still not what I was imagining but it does the job due to all the values that I need to change being in column L.

    Please Login or Register  to view this content.

+ 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