+ Reply to Thread
Results 1 to 12 of 12

Find and Replace Text within a cell

  1. #1
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    Find and Replace Text within a cell

    Hi Everyone

    I have a massive code list of 8000 items which I need to change specific entries within the string to a shorter code

    For example if the cell contains "DRINK FIZZY NICE BEVERAGE 10 PACK" I need it to say "DRINK FIZZY NICBVRG 10 PACK" so that the description now contains the code NICBVRG

    I have found this code which replaces the entire cell with the code instead of just changing the specified description in the string - please help as I really wouldn't like to have to go through line by line 8000 times - Many thanks all

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Find and Replace Text within a cell


    Hi,

    in VBA inner help of Range.Replace method, just see its parameters (LookAt) …

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and Replace Text within a cell

    Does this help?

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Find and Replace Text within a cell

    Thanks Marc L, much appreciated however I am not 100% sure that this code works correctly as I've tried it but it appears to only replace the values with the items next to them

    Are you able to help with a code that will actually provide what I'm looking for? A find / replace macro for text combinations within a string of text as per my example

    My apologies as I am not very good with VBA (total newbie)

    Thanks

  5. #5
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Find and Replace Text within a cell

    Hi John H Davis

    Thanks for the response.. I think I may have left out some other key info..

    In column A, I have a list of 8000 lines containing the descriptions (or similar) to "DRINK FIZZY NICE BEVERAGE 10 PACK"
    In Column B, I have a code list which contains the "NICBVRG" as well as other codes that will need to be replaced in Column A

    Hopefully that provides more clarity on what I'm trying to achieve

    Thanks again

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Find and Replace Text within a cell

    Word of advice.
    Load both ranges in Array, performe replacement in memory and write changed Array back to Range. This will shorten execution time signifficantly.
    Please post example file for us that represents actual situation to work with.

  7. #7
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and Replace Text within a cell

    Maybe:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Find and Replace Text within a cell

    Here is the file - i've added notes but here's a summary

    Column A contains the original partially coded descriptions
    Column B contains what description should be replaced in Column A
    Column C contains the code that should be present in Column A

    If more info is required let me know

    Thanks everyone for your help

    P.S. I've not included my original code as I do not think it is quite correct and I'm sure you will have much better examples/versions than me
    Attached Files Attached Files

  9. #9
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Find and Replace Text within a cell

    Try this for starters. Results are displayed in column E.
    Please Login or Register  to view this content.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and Replace Text within a cell

    Try:

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    01-13-2010
    Location
    Oxford
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Find and Replace Text within a cell

    Hi John H. Davis

    Worked perfectly for what I was trying to achieve

    Thanks also to Bakerman2 for your help as I know I'll be able to use what I've learned for other projects
    Last edited by Dan_B; 09-07-2015 at 09:35 AM. Reason: SOLVED

  12. #12
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Find and Replace Text within a cell

    You're welcome. Glad to help out and thanks for the feedback. Please comply with Forum Rules and mark this thread as SOLVED. Refer too link for guidance.

    http://www.excelforum.com/forum-rule...rum-rules.html

+ 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. [SOLVED] Macro to find, replace text and calculate VAT in a cell
    By elgato74 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 10-26-2014, 07:33 AM
  2. [SOLVED] Find space text in a cell and replace with %20
    By SierraKilo78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2014, 08:14 AM
  3. [SOLVED] Find Cell - Replace Text in different cells on same row
    By seannydj in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-31-2014, 05:45 PM
  4. Find and replace in cell with large quantity of text
    By iwishiknew in forum Excel General
    Replies: 1
    Last Post: 08-27-2014, 04:22 PM
  5. Replies: 3
    Last Post: 02-14-2014, 08:08 AM
  6. find in excel replace in word: find/replace text in text boxes and headers
    By dean.rogers in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-10-2012, 12:40 PM
  7. Advanced find and replace specific text within a cell
    By visionwindowfilms in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-14-2011, 04:28 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