Hi Lillian -
I'm struggling a bit to understand your exact objective, so I've included 3
new versions below:
Lillian1: Makes a new sheet called "output" that lists records for UNMATCHED
names.
Lillian2: Makes a new sheet called "output" that lists records for MATCHED
names.
Lillian3: Looks up data for MATCHED names and displays the data on sheet2.
I think Lillian3 will do what you described in your most recent post.
All three versions assume that the name lists start in cell A1 of sheet2 and
sheet3.
--
Jay
---------------------------------------------------------------------------------------------
Sub Lillian1()
'Writes records for UNMATCHED names to new "output" sheet
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws As Worksheet
Application.DisplayAlerts = False
Set ws1 = Worksheets("sheet2")
Set ws2 = Worksheets("sheet3")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "output" Then ws.Delete
Next 'ws
ActiveWorkbook.Worksheets.Add after:=Worksheets("sheet3")
ActiveSheet.Name = "output"
wsRows = ws2.Rows.Count
ws2.Activate
Range("A1").Activate
Do
If Not InStr(1, ActiveCell.Value, "name") Then
If ws1.Range("A1:A" & wsRows).Find(ActiveCell.Value, lookat:=xlWhole) Is
Nothing Then
ActiveCell.EntireRow.Copy Destination:=Worksheets("output") _
.Range("A" & wsRows).End(xlUp).Offset(1, 0)
End If
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
Application.DisplayAlerts = True
End Sub
'----------------------------------------
Sub Lillian2()
'Writes records for MATCHED names to new "output" sheet
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws As Worksheet
Application.DisplayAlerts = False
Set ws1 = Worksheets("sheet2")
Set ws2 = Worksheets("sheet3")
For Each ws In ActiveWorkbook.Worksheets
If ws.Name = "output" Then ws.Delete
Next 'ws
ActiveWorkbook.Worksheets.Add after:=Worksheets("sheet3")
ActiveSheet.Name = "output"
wsRows = ws2.Rows.Count
ws1.Activate
Range("A1").Activate
Do
If Not InStr(1, ActiveCell.Value, "name") Then
If Not ws2.Range("A1:A" & wsRows).Find(ActiveCell.Value,
lookat:=xlWhole) Is Nothing Then
ws2.Range("A1:A" & wsRows).Find(ActiveCell.Value,
lookat:=xlWhole).EntireRow.Copy _
Destination:=Worksheets("output").Range("A" &
wsRows).End(xlUp).Offset(1, 0)
End If
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
Application.DisplayAlerts = True
End Sub
'----------------------------------------
Sub Lillian3()
'Looks up data for matching names
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim ws As Worksheet
Dim refrng As Range
Dim f As Range
Set ws1 = Worksheets("sheet2")
Set ws2 = Worksheets("sheet3")
wsRows = ws2.Rows.Count
ws1.Activate
Range("A1").Activate
Set refrng = ws2.Range("A1:A" & wsRows)
Do
If Not InStr(1, ActiveCell.Value, "name") Then
If Not refrng.Find(ActiveCell.Value, lookat:=xlWhole) Is Nothing Then
Set f = refrng.Find(ActiveCell.Value, lookat:=xlWhole)
Range(f.Offset(0, 1), f.Offset(0, 2)).Copy ActiveCell.Offset(0, 1)
End If
ActiveCell.Offset(1, 0).Select
End If
Loop Until ActiveCell = ""
ws1.Range("A1").Select
End Sub
'-------------------------------------------------