Vba format date

Résolu/Fermé
tt - Modifié le 29 mars 2018 à 11:35
 tt - 30 mars 2018 à 14:48
Bonjour,

je vous sollicite sur un problème de format date, après avoir croisé deux fichiers, je me retrouve avec des dates en texte et des dates au format "dd/mm/yyyy"

le texte se trouve sous la forme : 01 - JAN - 2018

je traite donc avec le code ci dessous,

For Each Cel In Sheets("A).Range(Cells(2, 29), Cells(Derligne_A, 29))
        If Cel Like "*-*" Then
            If Mid(Cel, 4, 3) = "JAN" Then
                Cel.Value = Left(Cel, 2) & "/" & "01" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "FEV" Then
                Cel.Value = Left(Cel, 2) & "/" & "02" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "MAR" Then
                Cel.Value = Left(Cel, 2) & "/" & "03" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "AVR" Then
                Cel.Value = Left(Cel, 2) & "/" & "04" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "MAI" Then
                Cel.Value = Left(Cel, 2) & "/" & "05" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "JUI" Then
                Cel.Value = Left(Cel, 2) & "/" & "06" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "JUL" Then
                Cel.Value = Left(Cel, 2) & "/" & "07" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "AOU" Then
                Cel.Value = Left(Cel, 2) & "/" & "08" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "SEP" Then
                Cel.Value = Left(Cel, 2) & "/" & "09" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "OCT" Then
                Cel.Value = Left(Cel, 2) & "/" & "10" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "NOV" Then
                Cel.Value = Left(Cel, 2) & "/" & "11" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
            If Mid(Cel, 4, 3) = "DEC" Then
                Cel.Value = Left(Cel, 2) & "/" & "12" & "/" & "20" & Right(Cel, 2)
                Cel.Value = Format(Cel.Value, "dd/mm/yyyy")
            End If
        End If
    Next Cel


mais le format de la cellule n'est pas validée en date dd/mm/yyyy,

les dates restent sur la gauche, et je suis obligé de faire un double clic sur chaque ligne pour la prise en compte du nouveau format,

Est ce que vous avez une solution ?

Merci d'avance,
A voir également:

1 réponse

f894009 Messages postés 17185 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 15 avril 2024 1 701
29 mars 2018 à 17:18
Bonjour,

une facon de faire:
Sub test_Date()
    Derligne_A = 5        'mis pour tester a enlever
    For Each Cel In Sheets("A").Range(Cells(2, 29), Cells(Derligne_A, 29))
        If Cel Like "*-*" Then
            Mois = Mid(Cel, 4, 3)
            If Mois = "JAN" Then
                MoisN = "01"
            ElseIf Mois = "FEV" Then
                MoisN = "02"
            ElseIf Mois = "MAR" Then
                MoisN = "03"
            ElseIf Mois = "AVR" Then
                MoisN = "04"
            ElseIf Mois = "MAI" Then
                MoisN = "05"
            ElseIf Mois = "JUI" Then
                MoisN = "06"
            ElseIf Mois = "JUL" Then
                MoisN = "07"
            ElseIf Mois = "AOU" Then
                MoisN = "08"
            ElseIf Mois = "SEP" Then
                MoisN = "09"
            ElseIf Mois = "OCT" Then
                MoisN = "10"
            ElseIf Mois = "NOV" Then
                MoisN = "11"
            ElseIf Mois = "DEC" Then
                MoisN = "12"
            Else
            End If
            DDAte = Left(Cel, 2) & "/" & MoisN & "/" & "20" & Right(Cel, 2)
            Cel.Clear
            Cel.Value = DateValue(DDAte)
        End If
    Next Cel
End Sub
1
Bonjour,

C'est résolu,

merci
0