Changer l'année d'une date

pierrof

XLDnaute Occasionnel
Bonjour

J'ai une colonne de mon projet contenant des dates de fins de contrats.
Le nombre de ligne peut variée d'une dixaine à plusieurs milliers.

A l'aide d'une macro je souhaite changer l'année 2020 en 2010.
Je joint un fichier exemple
Merci
 

Pièces jointes

  • test45.xls
    25.5 KB · Affichages: 52

mromain

XLDnaute Barbatruc
Re : Changer l'année d'une date

bonjour pierrof,

je te propose ce code :
Code:
Sub test()
Dim nbLignes As Long, i As Long

    With ThisWorkbook.Sheets("Feuil1")
        nbLignes = .Range("E" & .Rows.Count).End(xlUp).Row
        
        For i = 10 To nbLignes
            If IsDate(.Range("E" & i)) Then
                If Year(.Range("E" & i)) = 2020 Then .Range("E" & i) = DateSerial(2010, Month(.Range("E" & i)), Day(.Range("E" & i)))
            End If
        Next i
    End With
End Sub

a+
 

Pierrot93

XLDnaute Barbatruc
Re : Changer l'année d'une date

Bonjour pierrof, romain,

c'est fait alors je donne...

Code:
Option Explicit
Sub test()
Dim c As Range
Application.ScreenUpdating = False
For Each c In Range("E10:E" & Range("E65536").End(xlUp).Row)
    If IsDate(c) Then
        If Year(c) = 2020 Then c = DateSerial(2010, Month(c), Day(c))
    End If
Next c
Application.ScreenUpdating = True
End Sub

@+
 

Discussions similaires

Statistiques des forums

Discussions
312 489
Messages
2 088 852
Membres
103 974
dernier inscrit
chmikha