Sub ContaTL()
Dim Vettore()
Dim Venditore As Range
Dim VenditoreIndex As Long
Dim NuovoVenditore As Boolean
Dim NuovoCliente As Boolean
Dim ClientCellVer As Range
Const NumVend = 1
Const NumCli = 2
Const NumOrd = 3
ReDim Vettore(1 To 3, 1 To 1)
With Sheets("sintesi")
Vettore(NumVend, 1) = .Range("A2")
Vettore(NumCli, 1) = 1
Vettore(NumOrd, 1) = 1
For Each Venditore In .Range(.Range("A3"), .Range("A3").End(xlDown))
NuovoVenditore = True
For VenditoreIndex = 1 To UBound(Vettore, 2)
If Vettore(NumVend, VenditoreIndex) = Venditore Then
NuovoVenditore = False
Vettore(NumOrd, VenditoreIndex) = Vettore(NumOrd, VenditoreIndex) + 1
NuovoCliente = True
For Each ClientCellVer In .Range(.Range("A2"), Venditore.Offset(-1, 0))
If ((ClientCellVer = Venditore) And (ClientCellVer.Offset(0, 1) = Venditore.Offset(0, 1))) Then
NuovoCliente = False
Exit For
End If
Next ClientCellVer
If NuovoCliente Then
Vettore(NumCli, VenditoreIndex) = Vettore(NumCli, VenditoreIndex) + 1
Exit For
End If
End If
Next VenditoreIndex
If NuovoVenditore Then
ReDim Preserve Vettore(1 To 3, 1 To UBound(Vettore, 2) + 1)
Vettore(NumVend, UBound(Vettore, 2)) = Venditore
Vettore(NumCli, UBound(Vettore, 2)) = 1
Vettore(NumOrd, UBound(Vettore, 2)) = 1
End If
Next Venditore
For VenditoreIndex = 1 To UBound(Vettore, 2)
Cells(VenditoreIndex + 1, 7).Value = Vettore(NumVend, VenditoreIndex)
Cells(VenditoreIndex + 1, 8).Value = Vettore(NumCli, VenditoreIndex)
Cells(VenditoreIndex + 1, 9).Value = Vettore(NumOrd, VenditoreIndex)
Cells(VenditoreIndex + 1, 10).Value = Vettore(NumCli, VenditoreIndex) / Vettore(NumOrd, VenditoreIndex)
Next VenditoreIndex
End With
MsgBox "x"
End Sub |