Here is how I solved the problem:
Public RawTestLocation, testLocation, testDate, autoDate, As String
Sub GetDate()
'Really this just needs the date and test location fields on the report sheet to be separated
RawTestLocation = ActiveSheet.Range("b44").Value
'remove the time which user S adds after an @ sometimes, because it occasionally uses . instead of : for the divider.
If InStr(RawTestLocation, "@") <> 0 Then testLocation = Left(RawTestLocation, InStr(RawTestLocation, "@") - 1)
'Prevent full stop at the end causing an error
If Right(testLocation, 1) = "." Then
testLocation = Left(testLocation, Len(testLocation) - 1)
End If
'format date in standard format
If testLocation = "" Then testLocation = RawTestLocation
testLocation = Replace(testLocation, ".", "/")
'check for date in middle of string
Dim StartOfDate As Integer
LastSlashInDate = InStrRev(testLocation, "/") - 5
testDate = Mid(testLocation, LastSlashInDate, 10)
If Not IsDate(testDate) = True Then
testDate = Mid(testLocation, LastSlashInDate, 8)
End If
'check for date at beginning of string
If Not IsDate(testDate) = True Then
testDate = Right(testLocation, 16)
End If
If Not IsDate(testDate) = True Then
testDate = Left(testLocation, 10)
End If
If Not IsDate(testDate) = True Then
testDate = Left(testLocation, 8)
End If
'Check for date at end of string
If Not IsDate(testDate) = True Then
testDate = Right(testLocation, 10)
End If
If Not IsDate(testDate) = True Then
testDate = Right(testLocation, 8)
End If
If IsDate(testDate) = True Then
testDate = CDate(testDate)
autoDate = True
End If
End Sub
So the sub checks for the date by identifying the last / in the string. If this fails it looks at the end for any date format, then at the beginning. The differing numbers (8, 10 & 16) are used to check for DD/MM/YY, DD/MM/YYYY and DD/MM/YY 00:00 formats.