Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default 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


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
Subtract if dates in the range between 2 dates. inta251 via OfficeKB.com Excel Worksheet Functions 2 March 1st 07 04:40 AM
How to subtract 2 dates to get number of days.....please Nick Excel Worksheet Functions 3 November 10th 06 01:03 PM
Subtract two dates Joe Excel Discussion (Misc queries) 2 February 8th 06 02:57 AM
Subtract time and dates with restrictions Michaela Excel Worksheet Functions 2 February 7th 05 04:21 PM
subtract dates jrh Excel Programming 1 March 4th 04 04:05 PM


All times are GMT +1. The time now is 08:13 AM.

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"