Jay:
Thanks again for the quick response. I have been dumping all the spreadsheets into one and sorting for dups that way. I just knew there had to be a better way but not being a programmer I was lost. As I mentioned in my last note, I changed the column titles in the macro to match my spreadsheet, but got an error. If you are willing to babysit me a bit, could we try to work this out? I really know nada about VBA programming or pivot tables....kinda lacking on time to learn the details. Let me know. Here is what I changed...just the column headers. Oh I have a space in the spreadsheets between "patient" and "initials"....actually the words are on two separate rows. Does this make a difference?
Sub test()
Dim ws As Worksheet, ws2 As Worksheet
Dim DupArray, UniqueCollection As New Collection
Dim Counter As Long, i As Long, LastRow As Long, j As Long
Dim TestString As String
Dim TestArray
Dim PatientInitialsCol As Integer
Dim DOBCol As Integer
Dim RaceCol As Integer
Dim SexCol As Integer
Dim fn As WorksheetFunction
Set fn = Application.WorksheetFunction
With ActiveSheet
InitCol = Application.Match("Initials", .Rows(1), 0)
DOBCol = Application.Match("DOB", .Rows(1), 0)
RaceCol = Application.Match("Race", .Rows(1), 0)
SexCol = Application.Match("Sex", .Rows(1), 0)
End With
For Each ws In ThisWorkbook.Worksheets
LastRow = ws.Cells.SpecialCells(xlCellTypeLastCell).Row
For i = 2 To LastRow
TestString = ws.Cells(i, PatientInitialsCol) & " | " _
& ws.Cells(i, DOBCol) & " | " _
& ws.Cells(i, RaceCol) & " | " _
& ws.Cells(i, SexCol)
On Error Resume Next
UniqueCollection.Add TestString, TestString
Err.Clear
On Error GoTo 0
Next i
Next ws
For Each ws In ThisWorkbook.Worksheets
LastRow = ws.Cells.SpecialCells(xlCellTypeLastCell).Row
For i = 2 To LastRow
TestString = ws.Cells(i, PatientInitialsCol) & " | " _
& ws.Cells(i, DOBCol) & " | " _
& ws.Cells(i, RaceCol) & " | " _
& ws.Cells(i, SexCol)
If UniqueCollection.Count Then
ReDim TestArray(1 To UniqueCollection.Count)
For j = 1 To UniqueCollection.Count
TestArray(j) = UniqueCollection(j)
Next j
End If
If IsError(Application.Match(TestString, TestArray, 0)) Then
Counter = Counter + 1
If Counter = 1 Then
ReDim DupArray(1 To Counter)
Else
ReDim Preserve DupArray(1 To Counter)
End If
DupArray(Counter) = TestString
Else
If UniqueCollection.Count Then
UniqueCollection.Remove Application.Match(TestString, TestArray, 0)
End If
End If
Next i
Next ws
Set ws2 = Worksheets.Add
ws2.Range("A1").Resize(UBound(DupArray) - LBound(DupArray) + 1, 1) = fn.Transpose(DupArray)
End Sub
thanks again.
tp