+ Reply to Thread
Results 1 to 3 of 3

Find, Replace with and then replace adjacent cell

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    22

    Find, Replace with and then replace adjacent cell

    Afternoon,

    I am trying to create a macro where it finds a a certain word in a column for example C. What i want it to do is find anything that says FWD_EUR and then replace that cell (e.g C2) with CASH_EUR_FWD and after it has done that it replaces the adjacent cell (e.g. D2) with EUR_FWD. I then want this to do the same with FWD_USD to CASH_USD_FWD and adjacent cell to USD_FWD.

    Thanks for any help.

    Craig

    (Complete Amateur)
    Last edited by Craig2097; 03-18-2009 at 01:41 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Find, Replace with and then replace adjacent cell

    Hi,

    One way:

    Sub Replace()
        Dim r As Range, x As Integer, st1(2), st2(2), st3(2)
        st1(1) = "FWD_EUR": st1(2) = "FWD_USD"
        st2(1) = "CASH_EUR_FWD": st2(2) = "CASH_USD_FWD"
        st3(1) = "EUR_FWD": st3(2) = "USD_FWD"
        With Worksheets(1).Range("c:c")
    
            For x = 1 To 2
                Set r = .Find(st1(x), LookIn:=xlValues)
                If Not r Is Nothing Then
                   
                    Do
                        r.Value = st2(x)
                        r.Offset(0, 1) = st3(x)
                        Set r = .FindNext(r)
                    Loop While Not r Is Nothing
                End If
            Next x
        End With
    End Sub
    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    02-17-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Find, Replace with and then replace adjacent cell

    Cheers Rich, works a treat although i had to change it to activesheet as it wouldnt at first. Thats good as it means i am learning.

+ 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