+ Reply to Thread
Results 1 to 6 of 6

Compare names and copy data on two sheets

Hybrid View

  1. #1
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Compare names and copy data on two sheets

    Here's one way...
    Option Explicit
    
    Sub Find()
    Dim i As Long, lRow As Long, Name As String, rng As Range
    Application.ScreenUpdating = False
    With Sheet1
        lRow = .Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To lRow
            Name = Range("A" & i)
            With Sheets("Sheet2").Range("A:A")
                    Set rng = .Find(What:=Name, _
                                    After:=.Cells(1), _
                                    LookIn:=xlValues, _
                                    LookAt:=xlWhole, _
                                    SearchOrder:=xlByRows, _
                                    SearchDirection:=xlPrevious, _
                                    MatchCase:=False)
                    If Not rng Is Nothing Then
                        Sheet1.Range("B" & i) = rng.Offset(, 1)
                        Sheet1.Range("C" & i) = rng.Offset(, 2)
                    Else
                        MsgBox "Name does not exist"
                    End If
            End With
        Next i
    End With
    Application.ScreenUpdating = True
    End Sub

    Edited:
    Or another
    Option Explicit
    
    Sub Find2()
    Dim cell As Range, rng As Range, Name As String
    Application.ScreenUpdating = False
    For Each cell In Sheet1.Range(Range("A2"), Range("A2").End(xlDown))
        Name = cell
        With Sheet2.Range("A:A")
            Set rng = .Find(Name, LookIn:=xlValues, lookat:=xlWhole)
                If Not rng Is Nothing Then
                    cell.Offset(, 1) = rng.Offset(, 1)
                    cell.Offset(, 2) = rng.Offset(, 2)
                End If
        End With
    Next cell
    Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by Sintek; 06-27-2017 at 04:16 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ 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. Replies: 6
    Last Post: 01-08-2014, 01:56 PM
  2. [SOLVED] Copy Numbers based on compare names in 2 Sheets
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2013, 02:01 PM
  3. [SOLVED] Macro to compare data between sheets and copy/paste
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-24-2012, 05:46 PM
  4. Data copy and paste to multiple sheets by renaming the names
    By Ignesh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2012, 02:37 PM
  5. macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet
    By prachi b in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-07-2012, 01:46 AM
  6. compare data in 2 columns across 2 sheets and then copy data
    By CH53 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2011, 04:59 AM
  7. Compare 2 sheets & copy unmatched data below
    By tek9step in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-27-2010, 10:57 AM
  8. Compare a value with value in other sheets and then COPY data into a sheet.
    By acsishere in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-28-2009, 03:05 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