Sheets(2).Rows("3:" & Rows.Count).Delete
ur = Range("a" & Rows.Count).End(xlUp).Row
uc = Cells(1, Columns.Count).End(xlToLeft).Column
r = 3
For i = 3 To ur
ct = False
If Cells(i, 1) <> "" Then
Set ctr = Sheets(2).Columns(1).Find(what:=Cells(i, 1), lookat:=xlWhole)
If Not ctr Is Nothing Then
firstaddress = ctr.Address
Do
If ctr.Offset(0, 1) = Cells(i, 1).Offset(0, 1) Then
ct = True
Exit Do
End If
Set ctr = Sheets(2).Columns(1).FindNext(ctr)
Loop While Not ctr Is Nothing And ctr.Address <> firstaddress
End If
If ct <> True Then
Sheets(2).Rows(r) = Rows(i).Value
Set fin = Columns(1).Find(what:=Cells(i, 1), after:=Cells(i, 1), lookat:=xlWhole)
If Not fin Is Nothing Then
Do
If Cells(i, 2) = fin.Offset(0, 1) Then
For j = 3 To uc Step 2
If Cells(fin.Row, j) <> "" Then
n = Cells(fin.Row, Columns.Count).End(xlToLeft).Column
Sheets(2).Range(Sheets(2).Cells(r, n - 1), Sheets(2).Cells(r, n)) = Range(Cells(fin.Row, j), Cells(fin.Row, j + 1)).Value
Exit For
End If
Next
End If
Set fin = Columns(1).FindNext(fin)
Loop While Not fin Is Nothing And fin.Row > i
End If
r = r + 1
End If
End If
Next
|