Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default comparing lists in 2 workbooks and de-duplicating

I have 2 workbooks each containing long lists of names and addresses.

I need to compare the surname in column B and the first line of the address
in column D of workbook 1 with the list in workbook 2 (columns C and D). If
the same info occurs in workbook 2 I want to delete the entire line from that
list.

Can you help please?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 272
Default comparing lists in 2 workbooks and de-duplicating

Alan, I'm not sure I understand exactly what you're after but this should
give you a good start:
Sub DeleteDups()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim r1 As Range
Dim r2 As Range
Dim r3 As Range
Dim lRow1 As Long
Dim lRow2 As Long
Dim FirstAddress As String
Set ws1 = Workbooks("YourBook1.xls").Worksheets("Yoursheet")
Set ws2 = Workbooks("YourBook2.xls").Worksheets("Yoursheet")
lRow1 = ws1.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Set r1 = ws1.Range("B1:B" & lRow1)
lRow2 = ws2.Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Set r2 = ws2.Range("C1:C" & lRow2)
For cnt = lRow2 To 1 Step -1
Set r3 = Nothing
FirstAddress = ""
Set r1 = ws1.Range("B" & cnt)
Set r3 = r2.Find(What:=r1, SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, LookAt:=xlWhole, MatchCase:=False)
If r3 Is Nothing Then GoTo NextCnt
If r3.Offset(, 1) = r1.Offset(, 2) Then
r1.EntireRow.Delete
Else
FirstAddress = r3.Address
Do
Set r3 = r2.FindNext
If r3.Offset(, 1) = r1.Offset(, 2) Then
r1.EntireRow.Delete
Exit Do
End If
Loop Until r3.Address = FirstAddress
End If
NextCnt:
Next
End Sub
--
Charles Chickering

"A good example is twice the value of good advice."


"Alan M" wrote:

I have 2 workbooks each containing long lists of names and addresses.

I need to compare the surname in column B and the first line of the address
in column D of workbook 1 with the list in workbook 2 (columns C and D). If
the same info occurs in workbook 2 I want to delete the entire line from that
list.

Can you help please?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Duplicating Workbooks luke1438 Excel Discussion (Misc queries) 1 August 11th 05 07:50 PM
Comparing two lists halem2[_44_] Excel Programming 0 October 15th 04 07:42 PM
Comparing Lists to Partial Lists depuyus[_7_] Excel Programming 0 August 5th 04 01:43 PM
COMPARING LISTS jay dean Excel Programming 3 June 11th 04 06:00 PM
Comparing 2 Lists Glenn Excel Programming 4 January 19th 04 02:07 PM


All times are GMT +1. The time now is 09:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"