View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Philosophaie Philosophaie is offline
external usenet poster
 
Posts: 110
Default Changing the Year in formatted Date

I am wanting to read the year from a cell who is formatted as a date and has
a date in it. If the year is not 2010 then I want to change it to 2010.

"Rick Rothstein" wrote:

It is a little unclear from your code exactly what you are trying to do
(Date is a built in function in VB), but assuming you have a real date
reference of some kind, just put it in where I show ThisYearsDate and the
DateAdd function (as structured) will add one year to that date. I show the
output being assigned to a variable named NextYearsDate, but you can output
it anywhere you need to (back into a cell, in a MsgBox, etc.)...

NextYearsDate = DateAdd("YYYY", 1, ThisYearsDate)

--
Rick (MVP - Excel)


"Philosophaie" wrote in message
...
I would like to change to year portion from 2009 to 2010 in multiple cells.
The cells are formatted as Date with *3/14/2001 selected

for k = 1 to 5
Sheets("Sheet1").Cells(k,2)=Date
if Date.year = 2009 then Date.year=2010
next k

Date.year is incorrect. How do I change and save the date?


.