Tier ligne par ordre Alphabetique

Bonjour le forum

Je cherche le moyen de trier une colone par ordre alphabetique avec une macro car j'ai environ 9000 lignes

( voir exemple)

12trier-ligne.xlsx (9.59 Ko)

J'ai beau chercher je ne trouve pas j'ai essayer avec l'option trier par ligne mais cela ne va pas .

Merci de votre aide

Bonjour,

Une première proposition.

A te relire.

Cdlt

12reinruof77.xlsm (18.68 Ko)
Public Sub Main()
Dim tbl As Variant, N As Long, i As Long
    With ActiveSheet
        N = .Cells(.Rows.Count, 1).End(xlUp).Row
        tbl = .Cells(2, 2).Resize(N - 1)
        For i = LBound(tbl) To UBound(tbl)
            tbl(i, 1) = Sort_a_string(tbl(i, 1))
        Next i
        .Cells(2, 2).Resize(N - 1).Value = tbl
    End With
End Sub

Private Function Sort_a_string(ByVal txt As String) As String
Dim arr As Variant, x As Long, y As Long, tmp As String, tmp2 As String
    txt = Replace(txt, " ", "")
    arr = Split(txt, ",")
    For x = LBound(arr) To UBound(arr)
        For y = x To UBound(arr)
            If UCase(arr(x)) > UCase(arr(y)) Then
                tmp = arr(x): tmp2 = arr(y)
                arr(x) = tmp2: arr(y) = tmp
            End If
        Next y
    Next x
    Sort_a_string = Join(arr, ", ")
End Function

bonjour Jean-Eric Jean Eric

Déjà merci

le seul problème que j'ai relever c'est que l'lorsque j'ai un mot composer (lundi matin, mardi soir, mercredi matin et soir)

je me retrouve avec (lundimatin, mardisoir, mercredimatinetsoir)

en effet les espace entre les mots sont supprimer .

comment modifier cela?

Merci de ton aide

Re,

J'ai modifié la fonction.

A tester.

La prochaine fois, soit plus précis dans ta demande.

Cdlt.

Private Function Sort_a_string(ByVal txt As String) As String
Dim arr As Variant, x As Long, y As Long, tmp As String, tmp2 As String
    txt = Application.Trim(txt)
    arr = Split(txt, ", ")
    For x = LBound(arr) To UBound(arr)
        For y = x To UBound(arr)
            If UCase(arr(x)) > UCase(arr(y)) Then
                tmp = arr(x): tmp2 = arr(y)
                arr(x) = tmp2: arr(y) = tmp
            End If
        Next y
    Next x
    Sort_a_string = Join(arr, ", ")
End Function

Re bonjour

Merci c'est exactement cela.

probleme résolu.

Rechercher des sujets similaires à "tier ligne ordre alphabetique"