Hi
Sorry, forgot about the duplicates.
Make sure that there is nothing on sheet3 (no headings etc). Sheets 1 and 2 have headings in row 1 and data starting in A2.
See how this goes.
Sub bbb()
Dim OutSH As Worksheet
Set OutSH = Sheets("Sheet3")
OutSH.Cells.ClearContents
Dim nodupes As New Collection
On Error Resume Next
With Sheets("sheet1")
For Each ce In .Range("A2:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
nodupes.Add Item:=ce.Value, key:=CStr(ce.Value)
Next ce
End With
With Sheets("sheet2")
For Each ce In .Range("A2:A" & .Cells(Rows.Count, 1).End(xlUp).Row)
nodupes.Add Item:=ce.Value, key:=CStr(ce.Value)
Next ce
End With
On Error GoTo 0
OutSH.Range("A1").Value = Sheets("Sheet1").Range("A1").Value
For i = 1 To nodupes.Count
OutSH.Range("A1").Offset(i, 0).Value = nodupes(i)
Next i
OutSH.Range("A1").CurrentRegion.Sort key1:=OutSH.Range("A1"), order1:=xlAscending, header:=xlYes
OutSH.Range("B1").Value = Sheets("Sheet1").Range("B1").Value
OutSH.Range("C1:D1").Value = Sheets("Sheet2").Range("B1:C1").Value
Set rng = OutSH.Range("A2:A" & OutSH.Cells(Rows.Count, 1).End(xlUp).Row)
With Sheets("sheet1")
For Each ce In rng
Set findit = .Range("A:A").Find(what:=ce)
If Not findit Is Nothing Then ce.Offset(0, 1).Value = findit.Offset(0, 1).Value
Next ce
End With
With Sheets("sheet2")
For Each ce In rng
Set findit = .Range("A:A").Find(what:=ce)
If Not findit Is Nothing Then
ce.Offset(0, 2).Value = findit.Offset(0, 1).Value
ce.Offset(0, 3).Value = findit.Offset(0, 2).Value
End If
Next ce
End With
End Sub
rylo
Bookmarks