Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need macro to add 100 years to a cell's date

I am using Office 2003. I know how to write a formula in a new cell and set
it equal to a different cell's date plus 100 years. I can then copy new
formula and paste special to original cell. But I sure can't figure out how
to do this with a macro. I am thinking I declare a variable as myDate, set
myDate = Cell(A1), then add 100 years to myDate, then pastespecial to
cell(a1). But I can't get this to work. Any help would be greatly
appreciated.
--
Bill W
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Need macro to add 100 years to a cell's date

Try this

Sub Add100()
Dim myDate As Date
myDate = Range("A1").Value
myDate = DateSerial(Year(myDate) + 100, Month(myDate), Day(myDate))
Range("A1").Value = myDate

End Sub

--
HTH,
Barb Reinhardt



"aligatrjoe" wrote:

I am using Office 2003. I know how to write a formula in a new cell and set
it equal to a different cell's date plus 100 years. I can then copy new
formula and paste special to original cell. But I sure can't figure out how
to do this with a macro. I am thinking I declare a variable as myDate, set
myDate = Cell(A1), then add 100 years to myDate, then pastespecial to
cell(a1). But I can't get this to work. Any help would be greatly
appreciated.
--
Bill W

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Need macro to add 100 years to a cell's date

One way:

With Range("A1")
.Value = DateAdd("yyyy", 100, .Value)
End With

In article ,
aligatrjoe wrote:

I am using Office 2003. I know how to write a formula in a new cell and set
it equal to a different cell's date plus 100 years. I can then copy new
formula and paste special to original cell. But I sure can't figure out how
to do this with a macro. I am thinking I declare a variable as myDate, set
myDate = Cell(A1), then add 100 years to myDate, then pastespecial to
cell(a1). But I can't get this to work. Any help would be greatly
appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need macro to add 100 years to a cell's date

Thank you Barb Reinhardt. Just what I was looking for. I could never find
the function DateSerial.
--
Bill W


"Barb Reinhardt" wrote:

Try this

Sub Add100()
Dim myDate As Date
myDate = Range("A1").Value
myDate = DateSerial(Year(myDate) + 100, Month(myDate), Day(myDate))
Range("A1").Value = myDate

End Sub

--
HTH,
Barb Reinhardt



"aligatrjoe" wrote:

I am using Office 2003. I know how to write a formula in a new cell and set
it equal to a different cell's date plus 100 years. I can then copy new
formula and paste special to original cell. But I sure can't figure out how
to do this with a macro. I am thinking I declare a variable as myDate, set
myDate = Cell(A1), then add 100 years to myDate, then pastespecial to
cell(a1). But I can't get this to work. Any help would be greatly
appreciated.
--
Bill W

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Need macro to add 100 years to a cell's date

Thanks JE McGimpsey. This gives me even more food for thought. I have
received two answers within 3 hours. I am very impressed with the help that
is available out there. Thanks again.
--
Bill W


"JE McGimpsey" wrote:

One way:

With Range("A1")
.Value = DateAdd("yyyy", 100, .Value)
End With

In article ,
aligatrjoe wrote:

I am using Office 2003. I know how to write a formula in a new cell and set
it equal to a different cell's date plus 100 years. I can then copy new
formula and paste special to original cell. But I sure can't figure out how
to do this with a macro. I am thinking I declare a variable as myDate, set
myDate = Cell(A1), then add 100 years to myDate, then pastespecial to
cell(a1). But I can't get this to work. Any help would be greatly
appreciated.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calc. an anniversary date(50 years) after marriage date in excel datakop Excel Worksheet Functions 3 January 4th 10 11:03 PM
Display another Cell's DATE value Here Michell Major Excel Discussion (Misc queries) 0 October 23rd 06 03:46 PM
How do I subtract a date from a date for a sum of total years? Paige Excel Discussion (Misc queries) 4 October 27th 05 03:10 PM
How do I make a cell's contents equal to another cell's contents with macro program? mgmcdevitt[_10_] Excel Programming 2 September 15th 05 09:44 PM
calculate no. of years between a date and today's date Sue Excel Worksheet Functions 10 June 14th 05 02:56 AM


All times are GMT +1. The time now is 08:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"