Date calculations in Excel 2016 VBA

ashgaroth

New Member
Joined
Mar 10, 2010
Messages
18
' The following block of code calculates the service user's age and turns on the 'Child' radio button _
if the service user is under 18 years of age.
' This works fine in Excel 2007 but crashes out in Excel 2016 with a compile error (can't find project or library) on the highlighted line.
' It seems to me that it is due to the missing Calendar Control that does not appear to be available for the 64 bit version of Excel 2016. I could be wrong, of course, and welcome your comments.
Code:
                txtAge2 = vbNullString
                txtDOB2 = vbNullString
                If Range("N" & Cnt) > vbNullString And _
                    Range("N" & Cnt) <> "Not recorded on AIS" Then
                    'Call date_and_time(Range("N" & Cnt))
                    [highlight]txtDOB2.Value = Format(Range("N" & Cnt), "dd/mm/yyyy")[/highlight]
                    FirstDate = txtDOB2
                    SecondDate = Date
                    Age = Year(SecondDate) - Year(FirstDate)
                    Mth = Month(SecondDate) - Month(FirstDate)
                    Day1 = Day(SecondDate) - Day(FirstDate)
                    Select Case Mth
                       Case Is < 0
                           txtAge2 = Age - 1
                       Case 0
                           Select Case Day1
                               Case Is < 0
                                   txtAge2 = Age - 1
                               Case Else
                                   txtAge2 = Age
                               End Select
                        Case Else
                            txtAge2 = Age
                    End Select

                    If txtAge2 < 18 Then
                        opChild2.Value = True
                    Else
                        opChild2.Value = False
                    End If

                Else
                    txtDOB2 = ""
                    txtAge = vbNullString
                End If
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top