Check date string value with IsDate

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have a list of dates strings entered as dd.mm.yy

These dates are added into an application that doesn't perform the validity of the entry and then exported into the file I am checking.

I need to check the entries to ensure they reflect an actual date, e.g. 32.01.21 will be flagged as invalid.

I thought by replacing the . character with a / character would work but the new value is interpreted as 22nd Jan 2032.

I have tried using DateSerial but this returns 1st Feb 2020.

If anyone can suggest a solution that doesn't required the original entry to be entered with a / instead of a . it would be appreciated.


Thanks
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Maybe try
Excel Formula:
 =Isnumber(Substitute(Date, ".", "/")+0)
 
Upvote 0
Sorry I should have stated that this check is happening via a VBA prcedure
 
Upvote 0
I assumed all entries (valid date or not) are text not date.
Try:

VBA Code:
Sub a1159782a()
'https://www.mrexcel.com/board/threads/check-date-string-value-with-isdate.1159782/
Dim i As Long
Dim tx As String
Dim va, vb, a

va = Range("A2", Cells(Rows.Count, "A").End(xlUp))
ReDim vb(1 To UBound(va, 1), 1 To 1)
For i = 1 To UBound(va, 1)
    vb(i, 1) = False
    tx = va(i, 1)
    
    If tx Like "##.##.##" Then
    a = Split(tx, ".")
        If a(0) < 32 And a(1) < 13 Then
            If Format(DateSerial(a(2), a(1), a(0)), "dd") = a(0) Then
                vb(i, 1) = True
            End If
        End If
    
    End If
Next

Range("B2").Resize(UBound(vb, 1), 1) = vb
End Sub


Book2
ABCDE
1DATE
232.01.21FALSE
303.12.23TRUE
445.23.12FALSE
547.08.21FALSE
630.02.22FALSEFebruary can't have 30
71.9.20FALSE
810.14.22FALSE
907.11.09TRUE
Sheet1
 
Upvote 0
Thanks Akuini

The specific issue I had, which I should have stated, is a date of 31.11.20 be entered.

also when an invalid date is detected I have a user form to pop up to ask for the correct date. So rather than returning a boolean, I need to leave a correct date, albeit using a . rather than a /, to stay in the cell and where invalid, the date entered via the userform replaces the incorrect date but in the format using a . as a seperator rather than a /.
 
Upvote 0
I need to check the entries to ensure they reflect an actual date, e.g. 32.01.21 will be flagged as invalid.
I don't quite understand what you want, I thought you you wanted to identify the invalid dates.
Do you mean you want to enter in format dd.mm.yy then use macro to convert it to dd/mm/yy?
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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