A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
you are totally confusing me
Why can we not do something here to these lines???
Aahh, good news, if I confuse you, then we come closer. :-)
I think I can now repeat something I have already said with a few more details:
If you write a text that looks like a date into a cell (the****cell format, except text, doesn't matter!) Excel tries to interpret the text as date, same way as CDate or DateValue does.
Furthermore: If you have a text that looks like a date (or time!) in a cell and you use a formula to calculate with that cell, Excel tries to interpret the text as date... same problem.
(I only say CDate in the following, you can replace it with DateValue or Excel)
And this date conversion has a few tricks in store, if you pass an incomplete or ambiguous date strings to the routine, it guesses which date you like, in respect to the local system settings.
An example:
Sub Test()
Range("A1") = CDate("14/1")
Range("A2") = CDate("1/14")
End Sub
Most systems in the world have DMY or MDY order, my is DMY, I don't know what your has...
Further details about the orders, have a look here at xlDateOrder:
https://docs.microsoft.com/en-ie/office/vba/api/excel.application.international
The conversation knows the first 2 parts are the day and the month. The 3rd part, the year, is missing. Therefore CDate uses the current year to calculate the real date (number).
A 14th month doesn't exists in the world, that means both dates are the 14 Jan 2020!
CDate assumes a typo and exchanges the day/month order.
And this happens every time when you write a text that looks like a date into a cell! No exception!
Sub Test()
Range("A1") = CDate("14/1")
Range("A2") = CDate("1/14")
Range("A3") = "14/1"
Range("A4") = "1/14"
End Sub
The problem arises when it is not clear what is the month or the day:
Sub Test()
Range("A1") = CDate("12/1")
Range("A2") = CDate("1/12")
Range("A3") = "12/1"
Range("A4") = "1/12"
End Sub
On my DMY system A1 is the 12 Jan 2020 and A2 is the 1 Dec 2020
On a MDY system the opposite is the case: A1 is the 1 Dec 2020 and A2 is the 12 Jan 2020
The 2 points where you struggle are:
a) The cell format doesn't matter
b) Never write a text that looks like a date into a cell
EDIT: Write the real date into the cell and the issue is gone, e.g.
.Cells(irow, 6) = ParseDate(frmincident.txtdatefinished)
Andreas.