Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Giuseppe,
se ho capito qual è il tuo problema io avrei creato una procedura che si limita, presi i dati che sono già presenti nella UserForm in base al suo caricamento iniziale, ad ordinarli.
Il problema che ho riscontrato è con le date che se inizialmente vengono caricate nel formato gg/mm/aaaa nella fase di ordinamento vengono visualizzate nel loro valore.
Io avevo trovato questa soluzione che però risulta essere lenta se il numero di voci da ordinare diventa "importante".
Questo il codice utilizzato da inserire nella userform (ad esclusione dell'evento Initialize che deve essere il tuo:
'----
Option Explicit
Option Compare Text
Const ColDate As Integer = 4
Private Sub UserForm_Initialize()
'N.B. sostituire il codice di caricamento dati iniziale con il proprio codice
With Me
With .ListBox1
.RowSource = "Elenco"
.ColumnCount = Range("Elenco").Columns.Count
End With
End With
End Sub
Private Sub CommandButton1_Click()
'N.B. utilizzare gli eventi Click in base al nome del proprio CommandButton
Call OrdinaListBox(0)
End Sub
Private Sub CommandButton2_Click()
'N.B. utilizzare gli eventi Click in base al nome del proprio CommandButton
Call OrdinaListBox(1)
End Sub
Private Sub CommandButton3_Click()
'N.B. utilizzare gli eventi Click in base al nome del proprio CommandButton
Call OrdinaListBox(2)
End Sub
Private Sub CommandButton4_Click()
'N.B. utilizzare gli eventi Click in base al nome del proprio CommandButton
Call OrdinaListBox(3)
End Sub
Sub OrdinaListBox(Colonna As Integer)
Dim arrLBi() As Variant, arrLBf() As Variant
Dim i As Long, t As Integer
With Me.ListBox1
ReDim arrLBi(LBound(.List, 1) To UBound(.List, 1), LBound(.List, 2) To UBound(.List, 2))
For i = LBound(.List, 1) To UBound(.List, 1)
For t = LBound(.List, 2) To UBound(.List, 2)
If t = ColDate - 1 Then
If Not IsNumeric(.List(i, t)) Then
arrLBi(i, t) = DateValue(.List(i, t))
Else
arrLBi(i, t) = .List(i, t)
End If
Else
arrLBi(i, t) = .List(i, t)
End If
Next t
Next i
arrLBi = SortArrayEasy(arrLBi, Colonna)
ReDim arrLBf(LBound(arrLBi, 1) To UBound(arrLBi, 1), LBound(arrLBi, 2) To UBound(arrLBi, 2))
For i = LBound(arrLBi, 1) To UBound(arrLBi, 1)
For t = LBound(arrLBi, 2) To UBound(arrLBi, 2)
If t = ColDate - 1 Then
arrLBf(i, t) = Format(arrLBi(i, t), "dd/mm/yyyy")
Else
arrLBf(i, t) = arrLBi(i, t)
End If
Next t
Next i
If .RowSource <> "" Then
.RowSource = ""
Else
.Clear
End If
.List = arrLBf()
End With
End Sub
Public Function SortArrayEasy(arrDati As Variant, col As Integer)
Dim temp As Variant
Dim i As Long, j As Long, t As Long
ReDim temp(LBound(arrDati, 2) To UBound(arrDati, 2))
For i = LBound(arrDati, 1) To UBound(arrDati, 1)
For j = i + 1 To UBound(arrDati, 1)
If arrDati(i, col) > arrDati(j, col) Then
For t = LBound(temp, 1) To UBound(temp, 1)
temp(t) = arrDati(i, t)
Next t
For t = LBound(temp, 1) To UBound(temp, 1)
arrDati(i, t) = arrDati(j, t)
Next t
For t = LBound(temp, 1) To UBound(temp, 1)
arrDati(j, t) = temp(t)
Next t
End If
Next j
Next i
SortArrayEasy = arrDati
End Function
'-----
Edit:
Qui trovi un file di esempio