+ Reply to Thread
Results 1 to 5 of 5

help for replace all macro

  1. #1
    Registered User
    Join Date
    03-10-2005
    MS-Off Ver
    Excel 2013
    Posts
    95

    help for replace all macro

    hi all,

    is there any way, any formula or macro to replace certain words in certain column?

    example :

    1. sheet1: in column C2:C1000 contain so many words and i need to replace/remove some of the word (usually you can do it by replace it manually.. ctrl+h then replace all, but if the words that you need to remove more than 50 words then it is painful)

    2. sheet2: column A : contain words that i need to remove

    so i need a way maybe macro that can read sheet2 column A and applied it as replace all in sheet1 column C

    is that possible?

    thanks guys
    Last edited by koi; 12-13-2011 at 11:34 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: help for replace all macro

    You need to more exact.... are you saying

    1) REMOVE all the words (strings) found listed on sheet2 column A from the LONGER strings on sheet1 column C? The matches are substrings from longer strings.

    This problematic in that if you removed "cat" it would change the word "catch" to "ch", too.

    2) REMOVE all the whole strings found listed on sheet2 column A from EXACT MATCH cells on sheet1 column C? The matches are to whole cells, not partial matches or substrings.

    3) REPLACE substrings, the replacement values would be on sheet2 column B>?

    4) REPLACE whole strings, the replacement values would be on sheet2 column B?


    It would really be simplest if you just posted a sample workbook showing examples of Sheet2 (list) and then Sheet1 BEFORE and AFTER. Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-10-2005
    MS-Off Ver
    Excel 2013
    Posts
    95

    Re: help for replace all macro

    hi,

    please find the sample,

    sheet1 : main work
    sheet2: replacement string/words
    desired : that is the final form that i wanted
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-10-2005
    MS-Off Ver
    Excel 2013
    Posts
    95

    Re: help for replace all macro

    hi,

    someone help me with this macro

    Sub bulkRemove2()
    Dim w As Range
    With Sheets("Sheet2")
    For Each w In .Range("A1", .Cells(Rows.Count, "A").End(xlUp))
    Sheets("Sheet1").Range("C:C").Replace what:=w.Value, replacement:=""
    Next w
    End With
    End Sub

    but it still have small weaknesses in that macro

    if you have in
    A1: R1
    A2 :R1a
    A3: R1b

    as the word to search and replace...then it will only replace R1 and leave the "a" and "b" word

    any advice how to tweak this macro to work so i will look for every column?

    thanks

    nb: it is solved just put the R1a first (longest word first then it is done)
    Last edited by koi; 12-13-2011 at 11:35 AM.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: help for replace all macro

    This is the main answer:
    Please Login or Register  to view this content.

    There is a problem in that in two of your sample strings you have two / marks and it is messing with those. Do you have more instances where there are additional / characters in the string? Are they all a consistent syntax?

    For instance, the two so far are:

    1EXTR/41011/R2C
    1EXTR/41011/AB

    We could put in code to fix this one instance by replacing 1EXTR/ with 1EXTR^^ before running the main macro, then changing it back. Are there more?

+ 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