MrExcel Publishing
Your One Stop for Excel Tips & Solutions

How Can I Increase A Date By 18 Months


Posted by Susan Smith on November 14, 2001 3:50 AM

Good Day,

I have just stumbled across this site, I am very new to VB and I was wondering if anyone can help me.

I have 3 txtboxes making up a date, lets call these tx1, tx2, tx3, what I want to do is when the date is punched in the boxes - dd/mm/yy, a date that 18 months greater is calculated for tx4, tx5, tx6 - dd/mm/yy. Is this possible?

Thanks,
Sue


Posted by Dank on November 14, 2001 4:04 AM

How about some code like this for each textbox where a date will be entered?

Private Sub tx1_AfterUpdate()
If IsDate(tx1.Value) Then tx4.Value = Format(CDate(tx1.Value) + 547, "dd/mm/yy")
End Sub

The 547 is appoximately how many days there are in 18 months.

Hope it helps,
Dan.

Posted by Juan Pablo on November 14, 2001 9:45 AM

Give this a try...

DateSerial(Year(txt1), Month(txt1) + 18, Day(txt1))

Juan Pablo