Sub Allinea()
Dim Righe, Trovato, k As Integer
Righe = Range("A:A").End(xlDown).Row
For i = 1 To Righe
Trovato = 0
For j = 1 To Righe
If Cells(i, 1) = Cells(j, 3) Then
Cells(i, 5) = Cells(i, 1)
Cells(i, 6) = Cells(i, 2)
Cells(i, 7) = Cells(j, 3)
Cells(i, 8) = Cells(i, 4)
Trovato = 1
End If
Next
If Trovato = 0 Then
Cells(i, 5) = Cells(i, 1)
Cells(i, 6) = Cells(i, 2)
Cells(i, 7) = ""
Cells(i, 8) = ""
End If
Next
k = 1
For i = 1 To Righe
Trovato = 0
For j = 1 To Righe
If Cells(i, 3) = Cells(j, 1) Then Trovato = 1
Next
If Trovato = 0 Then
Cells(Righe + k, 5) = ""
Cells(Righe + k, 6) = ""
Cells(Righe + k, 7) = Cells(i, 3)
Cells(Righe + k, 8) = Cells(i, 4)
k = k + 1
End If
Next
Columns("E:H").Select
Selection.Copy
Columns("A:D").Select
ActiveSheet.Paste
Columns("E:H").ClearContents
Range("A1").Select
End Sub |