
Option Explicit
Sub BuiltSummit()
Dim Lr As Integer, cell As Range, V As Range, M As Range, RisM As Range, LimInf As Integer, LimSup As Integer, Start As Single
Lr = Cells(Rows.Count, 1).End(xlUp).Row - 1 'Escludo l'ultima riga con i totali
Set M = Range("a4:a" & Lr) 'colonna dei codici delle Matrici
Set RisM = Range("i5:i26") 'colonna dei risultati aggregati
Start = Timer
[k5:l26].ClearContents
Dim Resa As Integer, kgEstr As Long
For Each cell In M
kgEstr = cell.Offset(, 1)
Resa = cell.Offset(, 3)
For Each V In RisM
LimInf = V
LimSup = V.Offset(, 1)
If Resa >= LimInf And Resa <= LimSup Then
V.Offset(, 2) = V.Offset(, 2) + 1
V.Offset(, 3) = V.Offset(, 3) + kgEstr
Exit For
End If
Next V
Next cell
MsgBox "Finito in sec: " & Round((Timer - Start), 1), vbInformation
End Sub
|
Sub Speed()
Dim Lr As Long, start, cell As Long
start = timer
Lr = Cells(Rows.Count, 1).End(xlUp).Row - 1 'Escludo l'ultima riga con i totali
Dim M As Variant, RisM As Variant, v As Long
M = Range("A4:E" & Lr) 'colonna dei codici delle Matrici
RisM = Range("I5:J26") 'colonna dei risultati aggregati
[k5:l26].ClearContents
Dim Resa As Integer, kgEstr As Long
Dim LimInf As Long, LimSup As Long
Dim K()
ReDim K(1 To 22, 1 To 2)
For cell = 1 To UBound(M)
kgEstr = M(cell, 2)
Resa = M(cell, 4)
For v = 1 To UBound(RisM)
LimInf = RisM(v, 1)
LimSup = RisM(v, 2)
If Resa >= LimInf And Resa <= LimSup Then
K(v, 1) = K(v, 1) + 1 'Ex Cells(v + 4, "K") = Cells(v + 4, "K") + 1
K(v, 2) = K(v, 2) + kgEstr 'Ex Cells(v + 4, "L") = Cells(v + 4, "L") + kgEstr
Exit For
End If
Next v
Next cell
Range("K5:L5").Resize(UBound(K, 1)) = K
MsgBox "Finito in sec: " & Round((timer - start), 1), vbInformation
End Sub
|
Sub BuiltSummit_HB()
Dim rng As Range, r As Byte, start As Single
Application.Calculation = xlCalculationManual
start = Timer
[k5:l26].ClearContents
[a3].AutoFilter
Set rng = [a3].CurrentRegion
For r = 6 To 26
rng.AutoFilter 4, ">=" & Str(Cells(r, "i") - 0.5), xlAnd, "<=" & Str(Cells(r, "j") + 0.5)
Cells(r, "k") = WorksheetFunction.Subtotal(3, rng.Columns(1)) - 1
Cells(r, "l") = WorksheetFunction.Subtotal(9, rng.Columns(2))
Next
[a3].AutoFilter
MsgBox "Finito in sec: " & Round((Timer - start), 1), vbInformation
Application.Calculation = xlCalculationAutomatic
End Sub |
da K5 in giù =CONTA.PIÙ.SE(D:D;">="&I5;D:D;"<="&J5) da L5 in giù =SOMMA.PIÙ.SE(B:B;D:D;">="&I5;D:D;"<="&J5) |
Sub Speed_Formula()
'--- Con un unico passaggio inserisco tutte le formule e riporto i valori nel range
With Range("K5:K26")
'--- Inserisci la formula colonna K sul foglio
.Formula = "=COUNTIFS(C[-7],"">=""&RC[-2],C[-7],""<=""&RC[-1])"
'--- Converti la formula in valore
.Value = .Value
'--- Inserisci la formula colonna L sul foglio
.Offset(, 1).Formula = "=SUMIFS(C[-10],C[-8],"">=""&RC[-3],C[-8],""<=""&RC[-2])"
'--- Converti la formula in valore
.Offset(, 1).Value = .Offset(, 1).Value
End With
End Sub |
