Option Explicit
Sub XXXX()
Dim Sh As Worksheet
Dim URiga As Long, URiga2 As Long
Dim i As Long, n As Long, Y As Long, Ind As Long, j As Long
Dim Indirizzo As String, Indirizzo2 As String
Set Sh = Sheets("FILE INIZIALE") ' da sostituire con il nome del foglio
URiga = Sh.Range("N" & Rows.Count).End(xlUp).Row
URiga2 = Sh.Range("A" & Rows.Count).End(xlUp).Row
ReDim Matrice(0 To URiga2 - 2, 1 To 7)
Sh.Range("N2:N" & URiga).Replace What:="Via", Replacement:="V."
For i = 2 To URiga
Indirizzo = Sh.Cells(i, 14) & Sh.Cells(i, 15)
For n = 2 To URiga2
Indirizzo2 = Sh.Cells(n, 2) & Sh.Cells(n, 3)
If Indirizzo = Indirizzo2 Then
For Y = 1 To 7
Matrice(Ind, Y) = Sh.Cells(n, Y)
Next Y
Sh.Cells(n, 1).ClearContents
Ind = Ind + 1
End If
Next n
Next i
For j = 2 To URiga2
If Sh.Cells(j, 1) <> "" Then
For Y = 1 To 7
Matrice(Ind, Y) = Sh.Cells(j, Y)
Next Y
Ind = Ind + 1
End If
Next j
Sh.Range("A2:G" & URiga2) = Matrice()
Set Sh = Nothing
End Sub
|