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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,052
Messages
6,122,878
Members
449,097
Latest member
dbomb1414

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