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, Riga As Long
Dim Lista As Range, x As Integer, ID As String
Set Sh1 = Sheets("Statistiche")
Set Sh2 = Sheets("Riepilogo")
LastRow = Sh1.Cells(Rows.Count, 1).End(xlUp).Row
LastRow2 = Sh2.Cells(Rows.Count, 1).End(xlUp).Row
Sh2.Range("A2:B" & LastRow2).ClearContents
ID = "ANALISI CLIENTE: *"
Riga = 2
Set Lista = Sh1.Range("A1:A" & LastRow)
Set Rng = Lista.Find(What:=ID, LookAt:=xlWhole, LookIn:=xlValues)
If Not Rng Is Nothing Then
firstAddress = Rng.Address
Do
x = InStr(Rng.Value, "(") - 1
Sh2.Cells(Riga, 1).Value = Mid(Rng.Value, 19, Len(Mid(Rng.Value, 1, x)) - 19)
Sh2.Cells(Riga, 2).Value = Rng.Offset(4, 11).Value
Riga = Riga + 1
Set Rng = Lista.FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> firstAddress
End If
LastRow2 = Sh2.Cells(Rows.Count, 1).End(xlUp).Row
Sh2.Range("A2:B" & LastRow2).Sort Key1:=Sh2.Range("B2"), Order1:=xlAscending, Header:=xlNo
Set Sh1 = Nothing
Set Sh2 = Nothing
Set Lista = Nothing
End Sub |