View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Felix Rode Felix Rode is offline
external usenet poster
 
Posts: 3
Default nonduplicative merge

I think the below will do the trick. It will create the sheet with the
unique ID's at the end automatically. It assumes that the relvant info is in
col 1 and 2 of each sheet. It will look in all sheets of the Active
Workbook. Didn't do a lot of validation, you might want to test it with a
small set of combinations first.
Hope this is what you are looking for, you can copy it right into a module.
Felix

Sub AgregateIDs()
Dim MySheet As Worksheet
Dim EndArray As Double
Dim MyArray
Dim i, ii, x1, x2
'Find the maximum number of combinations
For Each MySheet In ActiveWorkbook.Worksheets
EndArray = EndArray + MySheet.UsedRange.Rows.Count
Next

'Create an Array of the maximum size
ReDim MyArray(EndArray, 1)

'Fill the array with unique pairs
For Each MySheet In ActiveWorkbook.Worksheets
For i = 1 To MySheet.UsedRange.Rows.Count
x1 = CStr(MySheet.Cells(i, 1).Value)
x2 = CStr(MySheet.Cells(i, 2).Value)
For ii = 0 To EndArray
If x1 = MyArray(ii, 0) Then
If x2 = MyArray(ii, 1) Then Exit For
ElseIf MyArray(ii, 0) = Empty Then
MyArray(ii, 0) = x1
MyArray(ii, 1) = x2
Exit For
End If
Next
Next
Next

'Select the first sheet
Sheets(1).Select
'Add a new sheet
Sheets.Add

'Fill the sheet with unique ID Name combinations
For i = 0 To EndArray
ActiveSheet.Cells(i + 1, 1).Value = MyArray(i, 0)
ActiveSheet.Cells(i + 1, 2).Value = MyArray(i, 1)
If MyArray(i, 0) = Empty Then Exit For
Next

End Sub

"DrSteve" wrote in message
...
I have several sheets with the following 2 columns:

PersonnelCode Name

The sheets share some, but not all, information.
Generally each sheet has some PersonnelCode-Name pairs
that are unique to the sheet. The PersonnelCode and Name
sets are themselves one-to-one.

I would like to write a macro that will produce, in 2
corresponding columns on a master sheet, a nonduplicative
merge of all the columns of PersonnelCode and Name
information. I can do this with hooks into Excel from
some external DB/data processing apps, but would like to
do it all from within Excel if I can.

Many thanks in advance.