Qu'est-ce que je fais mal?
in cellule A2 J'ai un format de date (USA) 19790131. J'aimerais avoir cette réécriture dans le 31.01.1979 Entrez le code ici code> mais obtenir le résultat : 1/3/1979 p> For i = 2 To z
DatText = Cells(i, x)
Cells(i, x) = CDate(Mid(DatText, 7, 2) & "." & Mid(DatText, 5, 2) & "." & Mid(DatText, 1, 4))
Cells(i, x).NumberFormat = "dd.mm.yyyy"
Next i
3 Réponses :
Utilisez des barres obliques au lieu de périodes, donc CDate code> comprendra. Cells(i, x) = CDate(Mid(DatText, 7, 2) & "/" & Mid(DatText, 5, 2) & "/" & Mid(DatText, 1, 4))
Merci pour l'indice. Mais ce n'est pas ça.
Impair, car cela a fonctionné parfaitement bien quand je l'ai testé.
Si la date est une date Si la date est le numéro réel: strong> puis formater la cellule (NumberFormat) comme "yyyymmdd" code>, vous devez simplement modifier le format de cellule en "dd.mm.yyy" code> 19790131 code>, vous devez la convertir d'abord à une date réelle. Essayez: p> "dd.mm.yyy" code> p> p> p> p> p> p> P> P> P>
Vous pouvez utiliser format em> pour cela - et inclure isdate em> pour une manutention d'erreur: Public Function ConvertDate()
Dim ThisCell As Excel.Range
Dim RowIndex As Long
Dim ColumnIndex As Long
Dim DatText As String
ColumnIndex = 1
For RowIndex = 2 To 10
Set ThisCell = Cells(RowIndex, ColumnIndex)
If Not IsDate(ThisCell.Value) Then
DatText = Format(ThisCell.Value, "@@@@\/@@\/@@")
If IsDate(DatText) Then
ThisCell.Value = CDate(DatText)
End If
End If
Next
End Function