+ Reply to Thread
Results 1 to 6 of 6

Macro to find and replace cells in column that ends with certain text

  1. #1
    Registered User
    Join Date
    09-11-2015
    Location
    VA
    MS-Off Ver
    2010
    Posts
    30

    Macro to find and replace cells in column that ends with certain text

    Hello,

    I have a spreadsheet that has city name in column C and a state name in Column D. The issue is that sometimes the city and state are included both in Column C. I have listed these states in column f

    Is there a macro to find everything in column c that ends with everything in column f and removes these from column c?

    Attached same excel file for reference.

    So I want to remove MA and NY in C7 and C8

    Thanks again for the help!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Macro to find and replace cells in column that ends with certain text

    Just use a formula

    in G2
    =IF(" "&RIGHT(C2,2)=" "&D2,LEFT(C2,LEN(C2)-3),C2)
    and copy down the column

    Now copy column G, then Paste Values over the top of column C
    Delete column G
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,463

    Re: Macro to find and replace cells in column that ends with certain text

    Try below code:

    PHP Code: 
    Sub rpla()
    Dim arr(), sArri
    arr 
    Range("C2:" & [d65000].End(xlUp).Address)
    For 
    1 To UBound(arr)
        
    sArr Right(arr(i1), 3)
        If 
    arr(i2) = Trim(sArrThen _
        arr
    (i1) = Replace(arr(i1), sArr"")
    Next i
    Range
    ("C2:" & [d65000].End(xlUp).Address) = arr
    End Sub 
    Attached Files Attached Files
    Last edited by bebo021999; 08-08-2016 at 10:48 AM.
    Quang PT

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to find and replace cells in column that ends with certain text

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  5. #5
    Registered User
    Join Date
    09-11-2015
    Location
    VA
    MS-Off Ver
    2010
    Posts
    30

    Re: Macro to find and replace cells in column that ends with certain text

    Thanks to all --- Mumps1 did the trick!!

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,820

    Re: Macro to find and replace cells in column that ends with certain text

    Glad to help.

+ 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 for find/replace specific text within a column
    By majkkali in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2015, 10:59 AM
  2. Find and replace function with an "ends with" capability
    By B24Mike in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-26-2015, 04:49 PM
  3. Replies: 3
    Last Post: 11-25-2014, 06:08 AM
  4. [SOLVED] Search through columns and find specific text and replace that text with header column
    By adamzee in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-09-2014, 11:59 PM
  5. [SOLVED] Macro to Find & Replace existing formula with text in referenced cells
    By sonyap in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-07-2013, 10:39 AM
  6. [SOLVED] VBA to Search a Text String, Find a Value listed in another column and replace the text
    By Jschrod303 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-16-2012, 08:56 PM
  7. Need a Macro to do a find and replace for multiple text in just one column only
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-10-2012, 12:47 PM

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