Opération sur les dates

Toug

XLDnaute Junior
Bonjour,
Je souhaiterais soustraire en vba 3 mois à chaque date stockée dans les cellules de la colonnes C.
Je ne vois pas trop comment faire.

Merci.
 

Fred0o

XLDnaute Barbatruc
Re : Opération sur les dates

Bonjour Toug

Si tu veux stocker les valeurs dans la même ligne mais en colonne D, le code sera celui-ci (on démarre à la cellule C2) :
VB:
    For i = 2 To Range("C65536").End(xlUp).Row
        Range("D" & i) = DateSerial(Year(Range("C" & i)), Month(Range("C" & i)) - 3, Day(Range("C" & i)))
    Next

A+
 

fanfan38

XLDnaute Barbatruc
Re : Opération sur les dates

Bonjour

Sub test()
Dim madate As Date
Dim varjour As Byte
Dim varmois As Integer
Dim varan As Integer
derlig = Range("c" & Cells.Rows.Count).End(xlUp).Row
For i = 1 To derlig
madate = Cells(i, 3).Value
varjour = Day(madate)
varmois = Month(madate) - 3
varan = Year(madate)
If varmois < 1 Then varmois = 12 + varmois
Cells(i, 4).Value = CDate(varjour & "/" & varmois & "/" & varan)
Next
End Sub

ou Cells(i, 4).Value =Cells(i, 3).Value -91 ....

A+ François
ps: salut fredoo...c'est encore + simple autant pour moi...j'avais oublié dateserial...
 
Dernière édition:

mapomme

XLDnaute Barbatruc
Supporter XLD
Re : Opération sur les dates

Bonjour,
Grillé sur la ligne! Essayez ce code:
Code:
Sub Plus3mois()
Dim xCell As Range
With ActiveSheet
    For Each xCell In Range(.Cells(1, 3), .Cells(.Rows.Count, 3).End(xlUp))
    If IsDate(xCell) Then xCell = DateSerial(Year(xCell), Month(xCell) - 3, Day(xCell))
    Next xCell
End With
End Sub
 

Toug

XLDnaute Junior
Re : Opération sur les dates

Merci beaucoup, j'ai pris la ligne qui m'interressait, à savoir:
Code:
xCell = DateSerial(Year(xCell), Month(xCell) - 3, Day(xCell))

ça marche nickel
Bonjour,
Grillé sur la ligne! Essayez ce code:
Code:
Sub Plus3mois()
Dim xCell As Range
With ActiveSheet
    For Each xCell In Range(.Cells(1, 3), .Cells(.Rows.Count, 3).End(xlUp))
    If IsDate(xCell) Then xCell = DateSerial(Year(xCell), Month(xCell) - 3, Day(xCell))
    Next xCell
End With
End Sub
 

Discussions similaires

Réponses
11
Affichages
588

Statistiques des forums

Discussions
312 571
Messages
2 089 797
Membres
104 275
dernier inscrit
Manu974