Sub cerca()
Dim sh1 As Worksheet: Set sh1 = Worksheets("Foglio1") ' da cambiare casomai
Dim sh2 As Worksheet: Set sh2 = Worksheets("Foglio2") ' da cambiare casomai
Dim sh3 As Worksheet: Set sh3 = Worksheets("Risultato") ' da cambiare casomai
Dim Riga As Long, Lr As Long, R As Long, RR As Long, Area As Range, Dove As Object
Lr = sh3.Cells(Rows.Count, "A").End(xlUp).Row
If Lr > 1 Then sh3.Range(sh3.Cells(2, 1), sh3.Cells(Lr, 10)).Clear
Lr = sh2.Cells(Rows.Count, "A").End(xlUp).Row
Set Area = sh2.Range("A1:A" & Lr)
Lr = sh1.Cells(Rows.Count, "A").End(xlUp).Row
RR = 2
For R = 1 To Lr
Set Dove = Area.Find(sh1.Cells(R, 1), LookIn:=xlValues)
If Not Dove Is Nothing Then
Riga = Dove.Row
sh1.Range(sh1.Cells(R, 1), sh1.Cells(R, 2)).Copy
sh3.Cells(RR, 1).PasteSpecial
sh2.Range(sh2.Cells(Riga, 2), sh2.Cells(Riga, 10)).Copy
sh3.Cells(RR, 3).PasteSpecial
RR = RR + 1
End If
Next R
MsgBox "Fatto"
Set Area = Nothing
Set sh1 = Nothing
Set sh2 = Nothing
Set sh3 = Nothing
End Sub |