Trie par date et heure avec VBA

NICOALBERT

XLDnaute Occasionnel
Bonsoir le Forum,

J'ai un fichier avec des dates et heure dans 2 colonnes différentes et je cherche à les trier du 31/12 au 01/01 et la même chose pour les heures

exemple :

31/12/2016 03h00
31/12/2016 02h00
31/12/2016 01h00
.........
01/01/2016 03h00
01/01/2016 02h00

le mieux serait en VBA car j'ai plusieurs fichiers sur plusieurs année

J'ai bien tenté de le faire avec le filtre mais ça mélange tout :mad:

Cdlt Nicoalbert
 

Pièces jointes

  • trie date et heure.xls
    317.5 KB · Affichages: 72

ChTi160

XLDnaute Barbatruc
Bonsoir Nicoalbert
une approche
VB:
Sub Test()
    With Feuil1
       With .Range("A1").CurrentRegion
            .Columns(4) = Application.Substitute(.Columns(4), "h", ":")
            .Sort Cells(1, 3), xlAscending, Cells(1, 4), , xlAscending, , , xlGuess
       End With
    End With
End Sub
bonne fin de Soirée
Amicalement
Jean Marie
 

JHA

XLDnaute Barbatruc
Bonjour le forum,
Bonjour Jean-Marie,

j'ai essayé de modifier ton code pour associer la date et l'heure mais il y a toujours une erreur sur le trie, peux tu m'éclairer?
Code:
Sub Test()
    With Feuil2
       With .Range("A1").CurrentRegion
            .Columns(16) = Application.Substitute(.Columns(4), "h", ":")
            .Columns(15) = "=RC[-12]+RC[+1]"
            .Sort Cells(1, 15), xlAscending
            .Columns(15).Select
            Selection.ClearContents
            .Columns(16).Select
            Selection.ClearContents
       End With
    End With
End Sub
JHA
 
Dernière édition:

ChTi160

XLDnaute Barbatruc
re
peut être comme ceci
le problème vient je pense du fait que les Colonnes 15 et 16 dans ton exemple ne sont pas prises en compte lors de la détermination de la Plage de référence ".Range("A1").CurrentRegion" elle ne comprends pas les Colonnes rajoutées ensuite !
voir avec ce code :
VB:
Sub Test()
    With Feuil2
       With .Range("A1").CurrentRegion
            .Columns(16) = Application.Substitute(.Columns(4), "h", ":")
            .Columns(15) = "=RC[-12]+RC[+1]"
        End With    
        With.Range("A1").CurrentRegion
                 .Sort Cells(1, 15), xlAscending
            .Columns(15).Select
            Selection.ClearContents
            .Columns(16).Select
            Selection.ClearContents
        End With
    End With
End Sub[/VB]
à tester !
Bonne fin de Journée
Amicalement
Jean marie
 

ChTi160

XLDnaute Barbatruc
Re
Si le problème c'est le format des heures tu aurais pu remettre les heures au format initial
VB:
Sub Test()
   With Feuil1
       With .Range("A1").CurrentRegion
            .Columns(4) = Application.Substitute(.Columns(4), "h", ":")
            .Sort Cells(1, 3), xlAscending, Cells(1, 4), , xlAscending, , , xlGuess
            .Columns(4) = Application.Substitute(.Columns(4), ":";"h")
       End With
   End With
End Sub[/vb]
Bonne fin de Soirée
Amicalement
Jean marie
 

Discussions similaires

Statistiques des forums

Discussions
312 185
Messages
2 086 010
Membres
103 090
dernier inscrit
Createlier