Option Explicit
Sub FindNext()
Dim Sh1 As Worksheet
Dim Sh2 As Worksheet, Rng As Range, firstAddress As String
Dim LastRow As Long, LastRow2 As Long, NumC As Integer
Dim Stringa As String, i As Long, ID
Set Sh1 = Sheets("Foglio1")
Set Sh2 = Sheets("Foglio2")
LastRow = Sh1.Cells(Rows.Count, 1).End(xlUp).Row
LastRow2 = Sh2.Cells(Rows.Count, 1).End(xlUp).Row
Sh1.Range("F2:F" & LastRow).Clear
For i = 2 To LastRow
ID = Sh1.Cells(i, 1)
With Sh2.Range("A2:A" & LastRow2)
Set Rng = .Find(What:=ID, LookAt:=xlWhole, LookIn:=xlValues)
If Not Rng Is Nothing Then
firstAddress = Rng.Address
Do
Sh1.Cells(i, 6).Value = Sh1.Cells(i, 6).Value & "-" & Rng.Offset(, 1).Value
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> firstAddress
End If
End With
Next i
For i = 2 To LastRow
Stringa = Cells(i, 6).Value
If Len(Stringa) - 1 > 0 Then
Cells(i, 6) = Right(Stringa, Len(Stringa) - 1)
End If
Next i
Set Sh1 = Nothing
Set Sh2 = Nothing
End Sub
|