Numero più grande
Buongiorno Aquilarossa64,
premetto che io reputo il VBA una ottima soluzione per molti problemi, le formule sono utilissime e efficienti, ma solo se in numero limitato nella cartella, poichè, diversamente, "appesantiscono molto" e "rallentano".
Inoltre sono, a volte, molto complesse, e poco chiare.
Il VBA permette di suddividere il problema in piccoli problemi, ed è più chiaro.
Entrambe le soluzioni sono appropriate, ma per problemi complessi è preferibile il VBA, che consiglio di approfondire.
Comunque, allego la soluzione VBA.
Il file contiene la macro PiuGrande, che si lancia con il pulsante posto nel foglio "Serie" (ho cambiato i nomi ai fogli per chiarezza).
Ma si può lanciare anche con ALT+F8 e cliccando "esegui" nella maschera che compare.
Viene chiesto se ripulire la colonna NumeroPiuGrande oppure no, prima dell'esecuzione.
Se non si ripulisce, le serie non presenti nei Dati, non vengono aggiornate.....
riporto di seguito la macro, che è già contenuta nel file.
Attenzione!
Se si cambia l'etichetta "SERIE" nel foglio "Serie" e/o "NUMERO" nel foglio "Dati" la macro non funziona.
Se si vuole cambiare, bisogna intervenire alla riga 2 e/o 7 della macro, e sostituire anche lì le etichette.
Buon lavoro e buon anno
Sub PiuGrande()
Set serie = Sheets("Serie")
Set cella = serie.Cells.Find("Serie", , , xlWhole)
If cella Is Nothing Then Exit Sub
riga = cella.Row: colonna = cella.Column
Set rngserie = serie.Cells(riga, colonna).CurrentRegion.Columns(1).Cells
Set dati = Sheets("Dati")
Set cella = dati.Cells.Find("Numero", , , xlWhole)
If cella Is Nothing Then Exit Sub
riga = cella.Row: colonna = cella.Column
Set rngdati = dati.Cells(riga, colonna).CurrentRegion.Columns(1).Cells
With rngdati
strser = ","
For Each c In rngdati
serie1 = c.Value
mat = Split(serie1, "-")
If UBound(mat) < 1 Then GoTo nextc
nr = Val(Trim(mat(0)))
ser = Trim(mat(1))
pos = InStr(1, strser, "," & ser & ",", vbTextCompare)
If pos > 0 Then GoTo nextc
strser = strser & ser & ","
Set cella = rngdati.Find("*" & ser, , , xlWhole)
r1 = cella.Row: rfound = r1
maxnr = 0
Do
serie1 = cella.Value
mat = Split(serie1, "-")
nr = Val(Trim(mat(0)))
If nr > maxnr Then maxnr = nr
Set cella = rngdati.FindNext(cella)
rfound = cella.Row
Loop Until rfound = r1
strmax = strmax & "," & maxnr
nextc:
Next c
End With
strser = Replace(strser, ",", "", 1, 1)
matserie = Split(strser, ",")
strmax = Replace(strmax, ",", "", 1, 1)
matmax = Split(strmax, ",")
'MsgBox strser & vbCr & strmax
With rngserie
risp = MsgBox("Cancellare NumeroPiuGrande già esistenti?", vbCritical + vbYesNo)
If risp = vbYes Then
rngserie.Offset(1, 1).ClearContents
End If
'Exit Sub
For Each ser In matserie
Set cella = .Find(ser, , , xlWhole)
If Not cella Is Nothing Then
nr = Val(matmax(i))
cella.Cells(1, 2).Value = nr
End If
i = i + 1
Next ser
End With
End Sub