imput of Date in textbox in European format

de ware

New Member
Joined
Feb 16, 2010
Messages
49
Hi,

I have a textbox in which I want to input several dates in European format ("dd/mm/yyyy").
How can I explain VBA the date in the textbox is in European format?

For example:

in textbox1: 01/13/2013

datum = textbox1.text
msgbox isdate(datum) should return false sice there are only 12 months
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try this function:

Code:
Sub Test()
    Debug.Print IsDateValid("01/13/2013")
    Debug.Print IsDateValid("13/01/2013")
End Sub

Public Function IsDateValid(theDate As String) As Boolean

    'Checks whether theDate is in the exact format dd/mm/yyyy and is a valid date
    
    Dim parts As Variant
        
    IsDateValid = False
    
    parts = Split(theDate, "/")
    If UBound(parts) = 2 Then
        If IsNumeric(parts(0)) And IsNumeric(parts(1)) And IsNumeric(parts(2)) Then
            If Len(parts(0)) = 2 And Len(parts(1)) = 2 And Len(parts(2)) = 4 Then
                If theDate = Format(DateSerial(parts(2), parts(1), parts(0)), "dd/mm/yyyy") Then
                    IsDateValid = True
                End If
            End If
        End If
    End If
    
End Function
If d/m/yyyy or dd/m/yyyy or d/mm/yyyy are acceptable input formats then the function will have to be modified slightly.
 
Upvote 0

Forum statistics

Threads
1,213,528
Messages
6,114,154
Members
448,553
Latest member
slaytonpa

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