- Codice: Seleziona tutto
Private Sub TrovaNS()
Set Ws2 = Worksheets("Attuali")
UR = Ws2.Range("B" & Rows.Count).End(xlUp).Row
Ws2.Range("R8:U" & UR).ClearContents
MaxR = 0
ContaS = 1
For RR = 8 To UR
RuS1 = Trim(Ws2.Range("B" & RR).Value) & Trim(Ws2.Range("C" & RR).Value) & Trim(Ws2.Range("D" & RR).Value)
RuS2 = Trim(Ws2.Range("B" & RR + 1).Value) & Trim(Ws2.Range("C" & RR + 1).Value) & Trim(Ws2.Range("D" & RR + 1).Value)
If RuS1 = RuS2 Then
If MaxR = 0 Then
MioMaxR = Ws2.Range("J" & RR).Value
MaxR = 1
End If
MinR = Ws2.Range("J" & RR + 1).Value
ContaS = ContaS + 1
Else
MaxR = 0
Ws2.Range("R" & RR).Value = ContaS
If Trim(Ws2.Range("N" & RR - 1).Value) = "Sto" Then
Ws2.Range("R" & RR).Value = 1
Ws2.Range("R" & RR - 1).Value = ContaS - 1
If Ws2.Range("J" & RR) = 0 Then
MinR = Ws2.Range("J" & RR - 1).Value
Ws2.Range("S" & RR - 1).Value = MinR
If Trim(Ws2.Range("N" & RR - 2).Value) = "Sto" Then
Ws2.Range("T" & RR - 1).Value = MioMaxR
Ws2.Range("U" & RR - 1).Value = MioMaxR - MinR
End If
Else
Ws2.Range("T" & RR - 1).Value = MioMaxR
Ws2.Range("U" & RR - 1).Value = MioMaxR - MinR
End If
Else
If ContaS > 1 Then
Ws2.Range("S" & RR).Value = MinR
Ws2.Range("T" & RR).Value = MioMaxR
Ws2.Range("U" & RR).Value = MioMaxR - MinR
End If
End If
ContaS = 1
If Ws2.Range("R" & RR).Value > 0 Then Ws2.Range("S" & RR).Value = Ws2.Range("J" & RR).Value
End If
Next RR
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
EDIT ore 7:30 - Modificata macro