Hi donifar,
Okay, here is that code:
Option Explicit
Sub MergeAddresses()
Dim Shts As New Collection 'collection of selected sheets
Dim NewWS As Worksheet 'new merged worksheet
Dim WS As Worksheet
Dim iWS As Integer
Dim iRow As Long 'row number on source worksheet
Dim iRows As Long 'number of rows on source worksheet
Dim nRow As Long 'row number on new worksheet
Dim nRows As Long 'number of rows on new worksheet
Dim mCount As Long 'count of added addresses
Dim nDups As Long 'duplicates skipped
'put selected sheets in collection in tab (priority) order
For Each WS In ActiveWindow.SelectedSheets
Shts.Add WS
Next WS
If Shts.Count = 1 Then
MsgBox "Merging requires more than one sheet selected", _
vbOKOnly, "Merge Addresses"
Exit Sub
End If
'create destination worksheet
Shts(1).Copy before:=Worksheets(1)
Set NewWS = ActiveSheet
mCount = 0
nDups = 0
nRows = NewWS.Cells(65536, 6).End(xlUp).Row
'loop through selected sheet collection
For iWS = 2 To Shts.Count
Set WS = Shts(iWS)
iRows = WS.Cells(65536, 6).End(xlUp).Row
For iRow = 2 To iRows
For nRow = 2 To nRows
'check address1 field
If NewWS.Cells(nRow, 6) = WS.Cells(iRow, 6) Then
If NewWS.Cells(nRow, 7) = WS.Cells(iRow, 7) Then
nDups = nDups + 1
GoTo SkipDup
End If
End If
Next nRow
mCount = mCount + 1
nRows = nRows + 1
WS.Rows(iRow).Copy Destination:=NewWS.Rows(nRow)
SkipDup:
Next iRow
Next iWS
MsgBox mCount & " rows added to " & Shts(1).Name & vbCr & _
nDups & " duplicates skipped.", vbInformation, _
"Merge Address Results"
End Sub
This code should be placed in a standard macro module. To do this go to the VBE (keyboard Alt-TMV), insert a new macro module (Alt-IM), and paste this code into the Code pane.
To run this macro on your workbook, first order your worksheet tabs in the priority order for merging the records. You can do this by just dragging the tabs with the mouse. Second, select just the tabs that you want merged. Then run the macro (Alt-TMM, select macro and Run).
Incidentally, I assumed that row 1 on each sheet is a header row, which is why
For iRow = 2 To iRows
For nRow = 2 To nRows
loops both start with row 2. If you have no header row start the loops with 1. If multiple header rows start the loops with the first row that contains addresses.
Let me know if you have any problems.
Damon