+ Reply to Thread
Results 1 to 2 of 2

How do you Subtract dates in VBA

  1. #1
    Registered User
    Join Date
    07-24-2005
    Posts
    5

    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

  2. #2
    Ronin
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1