Option Base 1
Sub MatriceValoreMassimo()
Dim tabella As Range
Dim Rng As Range
Dim lRiga As Integer
Dim priga As Integer
Dim matrice()
Dim sh As Worksheet
Dim sh1 As Worksheet
Application.ScreenUpdating = False
Set sh = ThisWorkbook.Worksheets("Sheet1")
Set sh1 = ThisWorkbook.Worksheets("Sheet2")
With sh
lRiga = .Range("A" & Rows.Count).End(xlUp).Row
Set Rng = Range("a1:f1")
numerocelle = 0
For Each cl In Rng
a = Cells(2, 7)
If cl = Cells(2, 7) Then
cl.Select
numerocelle = numerocelle + 1
End If
Next
End With
ReDim matrice(1 To numerocelle, 1 To 2)
a = Cells(2, 8)
l = 1
For Each cl In Rng
If cl = Cells(2, 7) Then
cl.Select
matrice(l, 1) = ActiveCell.Offset(a - 1, 0)
matrice(l, 2) = ActiveCell.Offset(a - 1, 0).Address
sh1.Activate
Cells(l, 1) = matrice(l, 1)
Cells(l, 2) = matrice(l, 2)
sh.Activate
l = l + 1
End If
Next
Application.ScreenUpdating = True
MsgBox UBound(matrice)
Cells(2, 9) = WorksheetFunction.Max(matrice)
MsgBox WorksheetFunction.Max(matrice)
Cells(2, 9) = WorksheetFunction.Max(matrice)
priga = sh1.Range("A" & Rows.Count).End(xlUp).Row
Set tabella = sh1.Range("a2", "b" & priga)
MsgBox WorksheetFunction.VLookup((sh.Range("i2")), Range("tabella"), 2, False)
Cells(3, 9) = WorksheetFunction.VLookup(Range("I2"), Range("tabella"), 2, False)
End Sub
|