![]() |
How do you Subtract dates in VBA
I am trying to get VBA to sutract a date inputed from a text box from todays date and then divide all by 365.25 to find age. I would like this to be the value of the variable, varAge. Once varAge is known I would VBA to input the rest of the information from the other textboxes into the sheet corresponding to the correct age. I can do this in the Excel formula bar but I cannot make it work in VBA. Can anyone help? Thank you. Preston -- postlp60 ------------------------------------------------------------------------ postlp60's Profile: http://www.excelforum.com/member.php...o&userid=25532 View this thread: http://www.excelforum.com/showthread...hreadid=397376 |
How do you Subtract dates in VBA
copy and paste this in your module (form or other module, except class)\
Sub MyProcedure() Dim MyAge If CDbl(Format(txtBirthDate, "mmdd")) = CDbl(Format(Date, "mmdd")) Then MyAge = DateDiff("yyyy", txtBirthDate, Date) Else MyAge = DateDiff("yyyy", txtBirthDate, Date) - 1 MsgBox "You are " & MyAge & " years old as of today" End Sub Ronin "postlp60" wrote: I am trying to get VBA to sutract a date inputed from a text box from todays date and then divide all by 365.25 to find age. I would like this to be the value of the variable, varAge. Once varAge is known I would VBA to input the rest of the information from the other textboxes into the sheet corresponding to the correct age. I can do this in the Excel formula bar but I cannot make it work in VBA. Can anyone help? Thank you. Preston -- postlp60 ------------------------------------------------------------------------ postlp60's Profile: http://www.excelforum.com/member.php...o&userid=25532 View this thread: http://www.excelforum.com/showthread...hreadid=397376 |
All times are GMT +1. The time now is 05:10 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com