I have two sheets i havea column of set names in sheet 1 column A and Sheet
2 has another list of names in column B.
I need a macro that compares both lists. If one of the names in Sheet2
Column B is not found in sheet 1 column A place that name in sheet 1 column B.
Try this. Did you mean that you wanted the missing name appended to
the end of the list in Sheet2 Column B or into Sheet1 Column B? Right
now, the code drops it into Sheet2.
Sub CompareNames()
Dim MyCell As Range
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim FoundCell As Range
Dim LRow As Integer
Dim LRow2 As Integer
Dim FndRange As Range
Set WS = Sheets("Sheet1")
Set WS2 = Sheets("Sheet2")
LRow = WS.Cells(Rows.Count, "A").End(xlUp).Row
LRow2 = WS2.Cells(Rows.Count, "B").End(xlUp).Row
WS2.Activate
For Each MyCell In WS.Range("A1:A" & LRow)
Range("B:B").Select
Set FoundCell = Cells.Find(What:=MyCell.Value, _
After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If FoundCell Is Nothing Then
WS2.Range("B" & LRow + 1).Value = MyCell.Value
LRow2 = LRow2 + 1
End If
Next
End Sub