Je récupère, en téléchargement dans un fichier, des dates en formats mixtes
français et anglais tel que
30/04/2009 pour le 30 avril, et dans une cellule au dessous 05/04/2009 pour
le 4 Mai 2009.
Mes opérations sur les dates ne marchent pas (les dates devraient être dans
un sens croissant, et à cause du format anglais, je ne sais plus gérer....)
Sub test() Dim Rg As Range, T, Sep As String Dim X, A As Long, B As Integer Dim C As Range Application.ScreenUpdating = False Sep = Application.International(xlDateSeparator) With Worksheets("feuil1") Set Rg = .Range("A2:B" & .Range("B65536").End(xlUp).Row) For Each C In Rg.Columns With C .Replace "/", "-" X = C End With
For A = 1 To UBound(X, 1) For B = 1 To UBound(X, 2) X(A, B) = CDate(X(A, B)) Next Next C.Clear C.NumberFormat = "DD/MM/YY" C.Value = X Next End With Application.ScreenUpdating = True End Sub
Correction importante :
Utilise ceci :
Sub test()
Dim Rg As Range, T, Sep As String
Dim X, A As Long, B As Integer
Dim C As Range
Application.ScreenUpdating = False
Sep = Application.International(xlDateSeparator)
With Worksheets("feuil1")
Set Rg = .Range("A2:B" & .Range("B65536").End(xlUp).Row)
For Each C In Rg.Columns
With C
.Replace "/", "-"
X = C
End With
For A = 1 To UBound(X, 1)
For B = 1 To UBound(X, 2)
X(A, B) = CDate(X(A, B))
Next
Next
C.Clear
C.NumberFormat = "DD/MM/YY"
C.Value = X
Next
End With
Application.ScreenUpdating = True
End Sub
Sub test() Dim Rg As Range, T, Sep As String Dim X, A As Long, B As Integer Dim C As Range Application.ScreenUpdating = False Sep = Application.International(xlDateSeparator) With Worksheets("feuil1") Set Rg = .Range("A2:B" & .Range("B65536").End(xlUp).Row) For Each C In Rg.Columns With C .Replace "/", "-" X = C End With
For A = 1 To UBound(X, 1) For B = 1 To UBound(X, 2) X(A, B) = CDate(X(A, B)) Next Next C.Clear C.NumberFormat = "DD/MM/YY" C.Value = X Next End With Application.ScreenUpdating = True End Sub