+ Reply to Thread
Results 1 to 4 of 4

Find String and Replace With Adjacent Cell

Hybrid View

Steve0492 Find String and Replace With... 06-29-2012, 04:45 PM
tigeravatar Re: Find String and Replace... 06-29-2012, 04:53 PM
Steve0492 Re: Find String and Replace... 06-29-2012, 05:08 PM
tigeravatar Re: Find String and Replace... 06-29-2012, 05:19 PM
  1. #1
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Find String and Replace With Adjacent Cell

    Hello,

    I am trying to do the following. I have two sheets. In sheet one a have a column of data (A). In sheet two I have two columns of data (B and C). I want to match each cell in A to B, and then return the adjacent value in C. Can anyone help me do this? I have been struggling with the Find and Replace VBA function. Thanks.

    Steve
    A VBA novice, excited to learn!

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find String and Replace With Adjacent Cell

    Steve,

    Give this a try:
    Sub tgr()
        
        Dim rngReplace As Range
        Dim rngFound As Range
        Dim arrReplace As Variant
        Dim ReplaceIndex As Long
        
        Set rngReplace = Sheets(1).Range("A1", Sheets(1).Cells(Rows.Count, "A").End(xlUp))
        arrReplace = rngReplace.Value2
        
        With Sheets(2).Columns("B")
            For ReplaceIndex = 1 To UBound(arrReplace, 1)
                .NumberFormat = "General"
                Set rngFound = .Find(arrReplace(ReplaceIndex, 1), .Cells(.Cells.Count), xlValues, xlWhole)
                If Not rngFound Is Nothing Then
                    arrReplace(ReplaceIndex, 1) = rngFound.Offset(, 1).Text
                    Set rngFound = Nothing
                End If
            Next ReplaceIndex
        End With
        
        rngReplace.Value = arrReplace
        
        Erase arrReplace
        Set rngReplace = Nothing
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: Find String and Replace With Adjacent Cell

    Tiger this works great! Thanks for the quick and helpful response. I look forward to figuring out exactly how it works.

    Steve

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Find String and Replace With Adjacent Cell

    You're very welcome

+ 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