I am very new to VBA and may have thrown myself into the deep end with my
first bash.
I have created a simple Excel file of athletes (to be used later in a Lotus
Approach Database [sorry MS]). If an athletes data is missing I have attempted
to create a macro to enable it to be entered, with some of the data being
provided by the macro - SeasonDate, JuniorDate.
The main issue I am having is with the user entered DateOfBirth. When
entered it is used to calculate two more values - SeasonAge and JnrSeasonAge. I
have declared the various dates as <Date> it would appear that I am having a
conflict between US dates (mm/dd/yyyy) and UK dates (dd/mm/yyyy). All is ok
when
the date is clearly non-US (e.g. 13th day...) but when there is a
possibility of either date being valid it prefers to convert it to US?
I have pasted the subject macro below.
Private Sub cmbOK_Click()
Dim varSeasonAge As Double
Dim varJnrSeasonAge As Double
Dim varSeasonDate As Date
Dim varJuniorDate As Date
Dim varDateOfBirth As Date
varSeasonDate = "01/09/2006"
varJuniorDate = "01/01/2007"
ActiveWorkbook.Sheets("Athletes").Activate
Range("A3").Select
Do
If IsEmpty(activecell) = False Then
activecell.Offset(1, 0).Select
End If
Loop Until IsEmpty(activecell) = True
activecell.Offset(0, 1) = txbAthleteID.Value
activecell.Offset(0, 2) = txbSurname.Value
activecell.Offset(0, 3) = txbForeName.Value
activecell.Offset(0, 4) = txbDateofBirth.Value
Selection.Value = Selection.Offset(0, 3).Value & " " & Selection.Offset(0, 2)
activecell.Offset(0, 8) = varJuniorDate
activecell.Offset(0, 9) = varSeasonDate
If activecell.Offset(0, 4) = "" Then
activecell.Offset(0, 5).Value = "No DoB"
activecell.Offset(0, 6).Value = "No DoB"
activecell.Offset(0, 7).Value = "No DoB"
ElseIf activecell.Offset(0, 4) <> "" Then
varDateOfBirth = activecell.Offset(0, 4)
activecell.Offset(0, 5).Value = (varSeasonDate - varDateOfBirth) / 365.31
activecell.Offset(0, 6).Value = (varJuniorDate - varDateOfBirth) / 365.31
End If
varSeasonAge = activecell.Offset(0, 5).Value
varJnrSeasonAge = activecell.Offset(0, 6).Value
If varSeasonAge < 13 Then
activecell.Offset(0, 7).Value = "U13"
ElseIf varSeasonAge < 15 Then
activecell.Offset(0, 7).Value = "U15"
ElseIf varSeasonAge < 17 Then
activecell.Offset(0, 7).Value = "U17"
ElseIf varJnrSeasonAge < 20 Then
activecell.Offset(0, 7).Value = "J"
ElseIf varSeasonAge < 95 Then
activecell.Offset(0, 7).Value = "S"
End If
End Sub