
Option Explicit
Sub massimi_ritardi_VF()
Dim tabella As Range
Dim c1 As Range, c2 As Range
Dim n1 As Integer, n2 As Integer
Dim i As Integer
Dim fA As String
Dim dict As Object
Dim v As Variant, riga As Range
Dim s As String, t As String
Sheets("ARCHIVIO").Select
Set tabella = Range("C2..I21")
Set dict = CreateObject("Scripting.Dictionary")
For n1 = 1 To 48
For Each riga In tabella.Rows
If riga.Cells(1) = "" Then Exit For
v = Application.Transpose(Application.Transpose(riga))
s = ";" & Join(v, ";") & ";"
For n2 = n1 + 1 To 49
If InStr(s, ";" & n1 & ";") > 0 And InStr(s, ";" & n2 & ";") > 0 Then
If n1 = 1 And n2 = 6 Then
Debug.Print n1 & "-" & n2 & " found in row " & riga.Row
End If
t = n1 & "-" & n2
If dict.exists(t) Then
If riga.Row - dict(t) > dict(t) Then
i = dict(t)
dict.Remove t
dict.Add t, riga.Row - 1 - i
End If
Else
dict.Add t, tabella.Rows.Count - riga.Row + 1
End If
End If
Next
Next
Next
Debug.Print "Max dist for 1-6: "; dict("1-6")
Sheets("Foglio3").Activate
Cells.Clear
Range("a1") = "n1": Range("b1") = "n2": Range("c1") = "ritardo"
i = 2
For Each v In dict
Cells(i, "A") = Split(v, "-")(0)
Cells(i, "B") = Split(v, "-")(1)
Cells(i, "C") = dict(v)
i = i + 1
Next
Range("A1").CurrentRegion.Sort Range("C3"), xlDescending, Header:=xlYes
End Sub
|
Sub massimi_ritardi_VF()
Dim tabella As Range
Dim c1 As Range, c2 As Range
Dim n1 As Integer, n2 As Integer
Dim i As Long
Dim fA As String
Dim dict As Object
Dim v As Variant, riga As Range
Dim s As String, t As String
Sheets("ARCHIVIO").Select
Set tabella = Range("C2..I10000")
Set dict = CreateObject("Scripting.Dictionary")
For n1 = 1 To 48
For Each riga In tabella.Rows
If riga.Cells(1) = "" Then Exit For
v = Application.Transpose(Application.Transpose(riga))
s = ";" & Join(v, ";") & ";"
For n2 = n1 + 1 To 49
If InStr(s, ";" & n1 & ";") > 0 And InStr(s, ";" & n2 & ";") > 0 Then
If n1 = 1 And n2 = 6 Then
Debug.Print n1 & "-" & n2 & " found in row " & riga.Row
End If
t = n1 & "-" & n2
If dict.exists(t) Then
If riga.Row - dict(t) > dict(t) Then
i = dict(t)
dict.Remove t
dict.Add t, riga.Row - 1 - i
End If
Else
dict.Add t, tabella.Rows.Count - riga.Row + 1
End If
End If
Next
Next
Next
Debug.Print "Max dist for 1-6: "; dict("1-6")
Sheets("RISULTATI").Activate
Cells.Clear
Range("a1") = "1° numero": Range("b1") = "2° numero": Range("c1") = "Ritardo"
i = 2
For Each v In dict
Cells(i, "A") = Split(v, "-")(0)
Cells(i, "B") = Split(v, "-")(1)
Cells(i, "C") = dict(v)
i = i + 1
Next
Range("A1").CurrentRegion.Sort Range("C3"), xlDescending, Header:=xlYes
End Sub |
Dim ur As Long '<<<< aggiungi
Sheets("ARCHIVIO").Select '<<<< invariato
ur = Cells(Rows.Count, "A").End(xlUp).Row '<<<< aggiungi
Set tabella = Range("C2..I" & ur) '<<<< modifica
|
If tbrows - dict(v)(1) <= 3 Then '<<< indicare qui il numero dei primi massimi ritardi da mostraree il successivo End If devono essere commentati per avere tutti i risultati.
