+ Reply to Thread
Results 1 to 8 of 8

looping replace function

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-16-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2013
    Posts
    176

    looping replace function

    I have a list of values in column A: for example:

    a1-hi
    a2-bye
    a3-whatever
    a4-dude!

    and i have a list on column B:

    b1- whatever
    b2 - dude!

    If a value in A matches with B, replace value from column A it a character |

    Thanks,

  2. #2
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: looping replace function

    replace value from column A it a character |
    Do what now??
    ~~LaffyAffy13~~

    If I have helped you solve your problem, please be sure to click at the bottom left of my post.

    Thanks.

  3. #3
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: looping replace function

    Are you comparing the values in column A to any value in column B? Or are you only comparing the values in column A to their adjacent cell in column B?

  4. #4
    Forum Contributor
    Join Date
    07-16-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2013
    Posts
    176

    Re: looping replace function

    replace cell a3 with "|" and cell a4 with "|" because those are on the list to be replace. The list to be replace is on column B. Note, i'm only giving an example of two items, the list of items to be replace will grow over time.

  5. #5
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: looping replace function

    Alright.

    Sub remove()
    Application.ScreenUpdating = False
    'yay
    Dim b As Range, a As Range
    Dim btext As String, atext As String
    
    For Each b In Range(Range("B1"), Cells(Rows.Count, 2).End(xlUp))
    
        btext = b.Text
        
        For Each a In Range(Range("A1"), Cells(Rows.Count, 1).End(xlUp))
    
        atext = a.Text
        
        If atext = btext Then a.FormulaR1C1 = "|"
        
        Next a
    
    Next b
    End Sub

  6. #6
    Forum Contributor
    Join Date
    07-16-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2013
    Posts
    176

    Re: looping replace function

    Very nice, repped and thank you. Loved the 'yay for screenupdating. I stumble around and found a solution myself as well.

    With ActiveSheet
    rptrange = .Cells(.Rows.Count, "b").End(xlUp).Row
    End With
        Columns("A:A").Select
        For Each cell In Range("b1:b" & rptrange)
        Selection.Replace What:=cell.Value, Replacement:="|", LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Next cell
    Last edited by igoodable; 08-08-2013 at 05:27 PM.

  7. #7
    Forum Contributor
    Join Date
    07-24-2012
    Location
    Denver, CO
    MS-Off Ver
    365
    Posts
    230

    Re: looping replace function

    Thanks! I try to make life more enjoyable sometimes

    Hey make sure to put code tags around your code. Next time you post some code somewhere, just highlight all of it and click the "#" in the text editor right above the text box. That way you don't get yelled at by moderators well, not really "yelled" at, but at least they won't constantly ask you to put them on.

  8. #8
    Forum Contributor
    Join Date
    07-16-2013
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2013
    Posts
    176

    Re: looping replace function

    noted, thanks again.

+ 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. Looping through values to Replace
    By vncntj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-22-2012, 11:13 AM
  2. [SOLVED] copy and replace data using looping macro
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2012, 05:17 AM
  3. Looping to replace particular word
    By newbie13 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-06-2009, 07:16 AM
  4. Replace Function:Replace" and type in
    By ronnyc in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-19-2007, 06:26 PM
  5. [SOLVED] Need help with looping function
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-15-2006, 06:15 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