I want to compare names from Column A in Sheet1 to Column B in Sheet2 and if the same copy from sheet2 and paste the entire row onto Sheet3.
Help! This compares first and last names - I just need one name. The code is not working.
[VBA]Public Sub MDC_Usage()
'*Use this Macro to compare names from two worksheets and print result in another
'Declaring variables
Dim Sh1 As Worksheet, Sh2 As Worksheet, Sh3 As Worksheet
Dim LCel As Range, Nm As Range, c As Range, Tgt As Range
Dim Rng As Range, firstaddress As String
Set Sh1 = Sheets("Users")
Set Sh2 = Sheets("Usage")
Set Sh3 = Sheets("Final")
With Sh1
'Get list of last names from Sh1
Set Rng = Range(.Cells(2, 1), .Cells(Rows.Count, 2).End(xlUp))
'Search those last names in Sh2
With Sh2.Columns(2)
For Each Nm In Rng
Set c = .Find(Nm, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
Do
'Check first names
If Nm.Offset(, 0) = c.Offset(, 0) Then
'Get next vacant cell
Set Tgt = Sh3.Cells(Rows.Count, 1).End(xlUp).Offset(1)
'Copy names
c.Offset(, -2).Resize(, 70).Copy Tgt
End If
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress
End If
Next
End With
End With
End Sub
[/VBA]