Add month to date

  • Thread starter Thread starter buggy
  • Start date Start date
B

buggy

I would like to add one month to a date in a cell overwriting it wit
the new date. For example Cell A1 has the date 9/1/2004 and when m
macro is run A1 becomes 10/1/2004.

I can easily do this with the DATE(Year(a1),Month(a1)+1,day(a1) in
cell but I need to run it from the macro and overwrite the existin
cell.

Any help is appreciated
 
buggy,
Try this

Sub ChangeDate()
Dim Newdate
Newdate = DateSerial(Year(Range("a1")), Month(Range("a1")) + 1,
Day(Range("A1")))
ActiveSheet.Range("a1").Value = Newdate
End Sub

Neil
 
Watch the line wrap for newdate
Neil

Neil said:
buggy,
Try this

Sub ChangeDate()
Dim Newdate
Newdate = DateSerial(Year(Range("a1")), Month(Range("a1")) + 1,
Day(Range("A1")))
ActiveSheet.Range("a1").Value = Newdate
End Sub

Neil
 
Hi
in VBA
with activesheet.range("A1")
..value=dateserial(year(.value),month(.value)+1,day(.value))
end with


Note: this may give you wrong result for dates such as 31-Jan-2004
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top