Intégrer "xlTextAsNumbers"

Bonjour à toutes et à tous,

Je vous souhaite une beau WE :)

Je me permets de vous solliciter car je n'arrive pas à intégrer cette notion :

image

dans mon code :

Sub tri()
Dim c As Range
Application.ScreenUpdating = False: Application.EnableEvents = False
With Range("j4:j" & Rows.Count)
    .NumberFormat = "dd/mm/yyyy" & vbLf & "hh:mm"
    .Sort .Cells(1), xlAscending, Header:=xlNo 'tri croissant
    For Each c In .Resize(ActiveSheet.UsedRange.Rows.Count)
        If IsDate(c) Then
            'c.RowHeight = 30
            c.WrapText = True
        End If
    Next
End With
[a1].Select
Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub

En remplacement de : "

.Sort .Cells(1), xlAscending, Header:=xlNo 'tri croissant

Auriez le bon code ?

Un grand merci par avance,

Amicalement,

lionel,

bonjour,

il s'agit d'un paramètre de l'objet sort, il faut donc modifier quelque peu ton code.

Sub tri()
    Dim c As Range, dl As Long
    Application.ScreenUpdating = False: Application.EnableEvents = False
    dl = Cells(Rows.Count, "J").End(xlUp).Row
    With Range("j4:j" & dl)
        .NumberFormat = "dd/mm/yyyy" & vbLf & "hh:mm"
    End With
    With ActiveSheet.Sort
        .SortFields.Clear
        .SortFields.Add2 Key:=Range("J4:J" & dl), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
        .SetRange Range("J4:J" & dl)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    For Each c In Range("j4:j" & dl)
        If IsDate(c) Then
            'c.RowHeight = 30
            c.WrapText = True
        End If
    Next
    [a1].Select
    Application.ScreenUpdating = True: Application.EnableEvents = True
End Sub

Bonjour h2so4,

lol, sans le faire exprès, j'ai bien fait d'attirer ton attention :)

Merci pour le code, c'est nickel,

Un grand merci,

Bon WE,

lionel :)

Rechercher des sujets similaires à "integrer xltextasnumbers"