Vba format date
Résolu
tt
-
tt -
tt -
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,
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,
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:
- Vba format date
- Format epub - Guide
- Format factory - Télécharger - Conversion & Codecs
- Hp usb disk storage format tool - Télécharger - Stockage
- Format dat - Guide
- Format apfs - Guide
1 réponse
Bonjour,
une facon de faire:
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
C'est résolu,
merci