Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Michele,
per approfondire le mie conoscenze su Excel sto cercando di apprendere il linguaggio VBA.
In un file, che allego, ho una tabella da B2 a G10 dove riporto dei numeri (nel mio esempio da 1 a 10) .
In colonna K e in colonna L rispettivamente riesco ad ottenere con formule il numero delle occorrenze (col. K) e il numero del ritardo rispetto all'ultima occorrenza (col. L) dei valori presenti in colonna J.
In colonna O e P vorrei ottenere con il VBA lo stesso risultato. Sono riuscito a risolvere solo il "conteggio delle occorrenze" e mi servirebbe un aiuto per quantificare i "ritardi"
link file
Prova qualcosa del genere:
'========>>
Option Explicit
'-------->>
Public Sub Ritardo()
Dim WB As Workbook
Dim SH As Worksheet
Dim srcRng As Range, rng\_Numeri As Range
Dim rng\_Ritardo As Range
Dim iRitardo As Long
Dim i As Long, LRow As Long, iCtr As Long
Const sFoglio As String = **"Numeri" '<<=== Modifica**
Const sIntervallo\_Sorgente As String = **"B2:G10" '<<=== Modific**
Const sIntervallo\_Numeri As String = **"J2:J11" '<<=== Modifica**
Const sIntervallo\_Ritardo As String = **"P2:P11" '<<=== Modifica**
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
Set srcRng = .Range(sIntervallo\_Sorgente)
Set rng\_Numeri = .Range(sIntervallo\_Numeri)
Set rng\_Ritardo = .Range(sIntervallo\_Ritardo)
End With
With srcRng
For i = 1 To rng\_Numeri.Cells.Count
iCtr = iCtr + 1
LRow = LastRow(SH, rng\_Numeri.Cells(i).Value, srcRng)
If CBool(LRow) Then
iRitardo = .Rows.Count - LRow + 1
rng\_Ritardo.Cells(i).Value = iRitardo
End If
Next i
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
iNumber As Long, \_
Optional Rng As Range, \_
Optional minRow As Long = 1)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:=iNumber, \_
After:=Rng.Cells(1), \_
Lookat:=xlPart, \_
LookIn:=xlFormulas, \_
SearchOrder:=xlByRows, \_
SearchDirection:=xlPrevious, \_
MatchCase:=False).Row
On Error GoTo 0
If LastRow < minRow Then
LastRow = minRow
End If
End Function
'<<========
===
Regards,
Norman