Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
calc. an anniversary date(50 years) after marriage date in excel | Excel Worksheet Functions | |||
Display another Cell's DATE value Here | Excel Discussion (Misc queries) | |||
How do I subtract a date from a date for a sum of total years? | Excel Discussion (Misc queries) | |||
How do I make a cell's contents equal to another cell's contents with macro program? | Excel Programming | |||
calculate no. of years between a date and today's date | Excel Worksheet Functions |