+ Reply to Thread
Results 1 to 2 of 2

Thread: VBA to Copy single row, find match in sheet2 & paste over

  1. #1
    Registered User
    Join Date
    07-29-2011
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    VBA to Copy single row, find match in sheet2 & paste over

    Hi

    I have 2 sheets each with the same column header data in both. (Columns A - BP)
    Sheet1 has over 1000 rows of data with a unique number in column A assigned to each row.

    Sheet2 has only one row (row 2) [row 1 has column headers].
    I need to copy the row in Sheet2, find the matching row in Sheet1 (Unique number in Column A). Once found, the copied data needs to be pasted over the existing data in that row in Sheet 1 using PasteSpecial values.

    Your assistance is greatly appreciated.
    Thanks
    Last edited by willaby; 08-01-2011 at 01:08 PM. Reason: Title clarification

  2. #2
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    PA
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    926

    Re: VBA to Copy single row, find match in sheet2 & paste over

    Hi, Give this a try:

    Option Explicit
    Sub copyfrom()
    Dim lrow As Long
    Dim rfound As Range
    Dim i As Integer
    Application.ScreenUpdating = False
        lrow = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
            With Sheets(2)
                For i = 2 To lrow
                    Set rfound = Sheets(1).Cells.Find(What:=.Cells(i, 1).Value, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
                    xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
                    , SearchFormat:=False)
     
                        If rfound Is Nothing Then
     
                        Else
                        Sheets(2).Cells(i, 1).EntireRow.Copy Sheets(1).Range(rfound.Address)
     
                        End If
     
     
                Next i
    End With
    Application.ScreenUpdating = True
    End Sub
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0