Bonjour a tous,
voilà mon problème, je souhaite trier, sous vba, une variable a deux
dimension. Ma variable contient une date et une chaine de caractère et je
souhaiterais non seulement faire un tri par date mais aussi supprimer les
doublons.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Ange Ounis
Pour supprimer les doublons, tu trouveras sûrement ton bonheur sur Excelabo (par exemple). Pour trier un tableau à deux dimensions, j'ai cette petite merveille en stock :
''''''''''''''''''''''''''''' 'tri quicksort sur un tableau à deux dimensions 'permet de choisir la colonne de tri (paramètre col) 'attention : ce paramètre doit tenir compte de la base du tableau (0 ou 1) 'si le tableau est de base 0, col=5 va trier sur la colonne F et non E 'permet aussi de choisir l'ordre de tri (ascendant ou descendant)
Sub aaTesterSort() Dim bAscending As Boolean Set rng = Range("A1").CurrentRegion vArr = rng.Value bAscending = True QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending Range("A20").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr End Sub
Sub QuickSort(SortArray, col, L, R, bAscending) 'Tom Ogilvy, mpep 'Originally Posted by Jim Rech 10/20/98 Excel.Programming 'Modified to sort on first column of a two dimensional array 'Modified to handle a second dimension greater than 1 (or zero) 'Modified to do Ascending or Descending Dim i, j, X, Y, mm
i = L j = R X = SortArray((L + R) / 2, col) If bAscending Then While (i <= j) While (SortArray(i, col) < X And i < R) i = i + 1 Wend While (X < SortArray(j, col) And j > L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend Else While (i <= j) While (SortArray(i, col) > X And i < R) i = i + 1 Wend While (X > SortArray(j, col) And j > L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend End If If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending) If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending) End Sub '''''''''''''''''''''''''''''
---------- Ange Ounis ----------
Bonjour a tous, voilà mon problème, je souhaite trier, sous vba, une variable a deux dimension. Ma variable contient une date et une chaine de caractère et je souhaiterais non seulement faire un tri par date mais aussi supprimer les doublons.
avez vous une idée
merci
Pour supprimer les doublons, tu trouveras sûrement ton bonheur sur Excelabo (par
exemple). Pour trier un tableau à deux dimensions, j'ai cette petite merveille
en stock :
'''''''''''''''''''''''''''''
'tri quicksort sur un tableau à deux dimensions
'permet de choisir la colonne de tri (paramètre col)
'attention : ce paramètre doit tenir compte de la base du tableau (0 ou 1)
'si le tableau est de base 0, col=5 va trier sur la colonne F et non E
'permet aussi de choisir l'ordre de tri (ascendant ou descendant)
Sub aaTesterSort()
Dim bAscending As Boolean
Set rng = Range("A1").CurrentRegion
vArr = rng.Value
bAscending = True
QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending
Range("A20").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr
End Sub
Sub QuickSort(SortArray, col, L, R, bAscending)
'Tom Ogilvy, mpep
'Originally Posted by Jim Rech 10/20/98 Excel.Programming
'Modified to sort on first column of a two dimensional array
'Modified to handle a second dimension greater than 1 (or zero)
'Modified to do Ascending or Descending
Dim i, j, X, Y, mm
i = L
j = R
X = SortArray((L + R) / 2, col)
If bAscending Then
While (i <= j)
While (SortArray(i, col) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j, col) And j > L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
Else
While (i <= j)
While (SortArray(i, col) > X And i < R)
i = i + 1
Wend
While (X > SortArray(j, col) And j > L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
End If
If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending)
If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending)
End Sub
'''''''''''''''''''''''''''''
----------
Ange Ounis
----------
Bonjour a tous,
voilà mon problème, je souhaite trier, sous vba, une variable a deux
dimension. Ma variable contient une date et une chaine de caractère et je
souhaiterais non seulement faire un tri par date mais aussi supprimer les
doublons.
Pour supprimer les doublons, tu trouveras sûrement ton bonheur sur Excelabo (par exemple). Pour trier un tableau à deux dimensions, j'ai cette petite merveille en stock :
''''''''''''''''''''''''''''' 'tri quicksort sur un tableau à deux dimensions 'permet de choisir la colonne de tri (paramètre col) 'attention : ce paramètre doit tenir compte de la base du tableau (0 ou 1) 'si le tableau est de base 0, col=5 va trier sur la colonne F et non E 'permet aussi de choisir l'ordre de tri (ascendant ou descendant)
Sub aaTesterSort() Dim bAscending As Boolean Set rng = Range("A1").CurrentRegion vArr = rng.Value bAscending = True QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1), bAscending Range("A20").Resize(UBound(vArr, 1), UBound(vArr, 2)).Value = vArr End Sub
Sub QuickSort(SortArray, col, L, R, bAscending) 'Tom Ogilvy, mpep 'Originally Posted by Jim Rech 10/20/98 Excel.Programming 'Modified to sort on first column of a two dimensional array 'Modified to handle a second dimension greater than 1 (or zero) 'Modified to do Ascending or Descending Dim i, j, X, Y, mm
i = L j = R X = SortArray((L + R) / 2, col) If bAscending Then While (i <= j) While (SortArray(i, col) < X And i < R) i = i + 1 Wend While (X < SortArray(j, col) And j > L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend Else While (i <= j) While (SortArray(i, col) > X And i < R) i = i + 1 Wend While (X > SortArray(j, col) And j > L) j = j - 1 Wend If (i <= j) Then For mm = LBound(SortArray, 2) To UBound(SortArray, 2) Y = SortArray(i, mm) SortArray(i, mm) = SortArray(j, mm) SortArray(j, mm) = Y Next mm i = i + 1 j = j - 1 End If Wend End If If (L < j) Then Call QuickSort(SortArray, col, L, j, bAscending) If (i < R) Then Call QuickSort(SortArray, col, i, R, bAscending) End Sub '''''''''''''''''''''''''''''
---------- Ange Ounis ----------
Bonjour a tous, voilà mon problème, je souhaite trier, sous vba, une variable a deux dimension. Ma variable contient une date et une chaine de caractère et je souhaiterais non seulement faire un tri par date mais aussi supprimer les doublons.