I have a loop, that loops all entries in a column:
Dim indexOfDATE As Integer
indexOfDATE = 3
Do Until indexOfDATE - 1 = Cells(Rows.Count, 2).End(xlUp).Row
Dim tempDate As String
tempDate = Replace(Sheets("Pirmie Ievaddati").Cells(indexOfDATE, 2).Value, ",", ".")
tempDate = Replace(tempDate, ".", "/")
indexOfDATE = indexOfDATE + 1
Loop
I need to check that my tempDate string variable is in a dd.MM.yyyy format how can i do this and if not, show message box, not fall down with an error?
EDIT:
I'm doing this:
Dim indexOfDATE As Integer
indexOfDATE = 3
Do Until indexOfDATE - 1 = Cells(Rows.Count, 2).End(xlUp).Row
Dim tempDate As String
tempDate = Replace(Sheets("Pirmie Ievaddati").Cells(indexOfDATE, 2).Value, ",", ".")
tempDate = Replace(tempDate, ".", "/")
Dim current As Date
current = Format(CDate(tempDate), "dd/mm/yyyy")
Sheets("Pirmie Ievaddati").Cells(indexOfDATE, 2).Value = current
indexOfDATE = indexOfDATE + 1
Loop
As you see the cell is a string cell, i need to ensure that tempDate string will be in a correct format before i do convertation or application will fall.
I want to show user message, that in Cell (,) he has incorrect data
Or maybe a Try Catch block on convertation - but i have failed to stop code execution after first error
dd.MM.yyyyordd/MM/yyyy?tempDateis in correct format (dd.MM.yyyyordd/MM/yyyy) or thattempDateis correct date?